简体   繁体   English

将CSS导航到div元素中的元素

[英]Navigate css to element in div element

I need to navigate my css to an element, which is an element(div). 我需要将css导航到一个元素,这是一个element(div)。 Like this: 像这样:

.element element {
  color: rgba(6, 132, 134, 255);
} 

How to do that? 怎么做? Info: element > .element didn't work, and .element element also didn't work. 信息: element > .element无效, .element element也无效。
I am trying to get the toolbar element. 我正在尝试获取toolbar元素。 (here is the element in html): (这是html中的元素):

<div class="main" id="main">
    <div class="toolbar">

    </div>
  </div>  

And I need to get the toolbar element in main, because there are more toolbars in other divs? 而且我需要在main中获得工具栏元素,因为其他div中有更多的工具栏?

Thanks in advance for your help. 在此先感谢您的帮助。

Based on your HTML, your CSS should look like this: 根据您的HTML,您的CSS应该如下所示:

.toolbar {
  color:rgba(6, 132, 134, 255);
}

But since you have other elements with the class toolbar , you can use specificity so that only the element with class toolbar within the element with the id main will use those styles: 但是,由于类toolbar还有其他元素,因此可以使用特殊性,以便只有id为main的元素中具有类toolbar的元素才能使用这些样式:

 #main .toolbar { color:rgba(6, 132, 134, 255); } 
 <div class="main" id="main"> <div class="toolbar"> This is some text. </div> </div> 

. is used to select elements with a specific class, and # is used to select elements with a specific id. 用于选择具有特定类的元素,而#用于选择具有特定ID的元素。 In your case to select the .toolbar nested within #main you would need: 你的情况来选择.toolbar嵌套在#main你将需要:

 #main .toolbar { color: rgba(6, 132, 134, 255); } 

That's pretty simple: 那很简单:

#main div.toolbar {
color: red;
}

This targets the DIV with the class TOOLBAR within an element with the id MAIN :) 这将针对ID为MAIN的元素中的类为TOOLBAR的DIV:

您的问题有点抽象,但是基于您添加的代码,我认为您正在尝试定位div“工具栏”,可以使用以下任何一种方法来完成此操作(以最佳顺序排列) :

  1. #main .toolbar { ... }
  2. .main .toolbar { ... }
  3. #main div { ... }
  4. .main div { ... }

you can select in many ways, but if you want to navigate from one to another you should use on CSS (to access the toolbar) 您可以通过多种方式进行选择,但如果要从一个导航到另一个,则应在CSS上使用(访问工具栏)

.main div {
  color: rgba(6, 132, 134, 255);
} 

or you can simply use the css class selector to select the element directly 或者您可以简单地使用css类选择器直接选择元素

.toolbar {
    color: rgba(6, 132, 134, 255);
}

but this will not display anything, in order to see any content, you have to use the height property, or insert some content 但这不会显示任何内容,为了查看任何内容,您必须使用height属性,或插入一些内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM