[英]targeting css class under specific div only
I have 我有
<div class="col-sm-1 col-1-box">
<span class="glyphicon glyphicon-ok"></span>
how can I use target glyphicon glyphicon-ok under this col-sm-1 col-1-box
class only? 如何才能在此
col-sm-1 col-1-box
类下使用目标glyphicon glyphicon-ok?
I tried with 我试过了
.col-1-box + .glyphicon .glyphicon-ok {
...
}
but that doesnt work, what I'm doing wrong? 但那不起作用,我做错了什么?
You also can Try: 你也可以尝试:
.col-1-box > .glyphicon.glyphicon-ok {
border: 1px solid black;
}
It's the direct child, not a recursive match. 这是直接的孩子,而不是递归的匹配。
'+' is for next sibling and space is for all child elements '+'用于下一个兄弟,空间用于所有子元素
As your HTML like this 就像你的HTML一样
<div class="col-sm-1 col-1-box">
<span class="glyphicon glyphicon-ok"></span>
</div>
then CSS 然后CSS
.col-1-box .glyphicon.glyphicon-ok {
...
}
You need to remove space between .glyphicon
and .glyphicon-ok
您需要删除
.glyphicon
和.glyphicon-ok
之间的.glyphicon
.col-1-box + .glyphicon.glyphicon-ok { border: 1px solid black; }
<div class="col-sm-1 col-1-box"></div> <span class="glyphicon glyphicon-ok">Lorem Ipsum</span>
试试这个
.col-sm-1.col-1-box .glyphicon.glyphicon-ok{.....}
Try this might be this will help 试试这可能会有所帮助
.col-sm-1 span.glyphicon{ color:red; }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class="col-sm-1 col-1-box"> <span class="glyphicon glyphicon-ok"></span>
you can see color of ok icon is black and i change it to red 你可以看到ok图标的颜色是黑色,我将其更改为红色
你可以使用>
直接孩子:
.col-sm-1.col-1-box > .glyphicon.glyphicon-ok { ... }
Wrap the HTML inside a span that has a unique id or class name. 将HTML包装在具有唯一ID或类名称的范围内。
<span class="awwwwyeah">
<div class="col-sm-1 col-1-box">
<span class="glyphicon glyphicon-ok"></span>
</div> <!-- I assume the div ends somewhere -->
</span>
Then you can access the elements with css 然后你可以用css访问元素
.awwwwyeah .col-1-box .glyphicon-ok{
color: blue;
}
The element+element selector is used to select elements that is placed immediately after (not inside) the first specified element.
元素+元素选择器用于选择紧接在第一个指定元素之后(而不是在其内部)的元素。 Quoting it directly from the w3schooldoc.
直接从w3schooldoc引用它。
For more details read element + element selector here. 有关详细信息,请在此处阅读元素+元素选择
Let's see an example 我们来看一个例子吧
.parentElement .childElement { /*Selected Children only*/ background: red; width: 50px; height: 50px; display: inline-block; } .notImmediate { background: blue; width: 30px; height: 30px; } .childElement + .childElement { /*Selected immediately after (not inside) */ border-right: 10px solid green; }
<div class="parentElement"> <div class="childElement"> <div class="notImmediate"></div> </div> <div class="childElement"></div> </div>
Your question is somewhat confusing! 你的问题有点令人困惑! Here are the two possible scenarios - Choose as per your requirement
以下是两种可能的情况 - 根据您的要求进行选择
body { color: #000; } /* scenario 1 */ .col-1-box + .glyphicon.glyphicon-ok { color: tomato; } /* scenario 2 */ .col-1-box .glyphicon.glyphicon-ok { color: aqua; }
<h1>Scenario 1</h1> <div class="col-sm-1 col-1-box"></div> <span class="glyphicon glyphicon-ok">OK</span> <hr> <h1>Scenario 2</h1> <div class="col-sm-1 col-1-box"> <span class="glyphicon glyphicon-ok">OK</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.