我无法控制标记,但这是如何渲染的。
<div class="div1">
<div class="div2">
<p>Dont not select me</p>
</div>
</div>
<div class="div1">
<strong>
<p>Do not select me </p>
</strong>
<div class="div2">
<p>Select me only with css </p>
</div>
</div>
我希望仅在p
周围有div2
的兄弟div1
时才定位strong
中的x = [0, 0, 0]
all(map(lambda v: v==0, x))
# Evaluates to True
x = [0, 1, 0]
all(map(lambda v: v==0, x))
# Evaluates to False
代码。
这可能吗?
更新: 我错了。
答案 0 :(得分:2)
使用adjacent sibling selector +
:
.div1 strong+.div2 p {
background: tomato;
}
&#13;
<div class="div1">
<div class="div2">
<p>Dont not select me</p>
</div>
</div>
<div class="div1">
<strong>
<p>Do not select me </p>
</strong>
<div class="div2">
<p>Select me only with css </p>
</div>
</div>
&#13;
答案 1 :(得分:1)
定位p
.div2
的孩子,strong
是strong ~ .div2 > p {
color: red;
}
的兄弟:
<div class="div1">
<div class="div2">
<p>Dont not select me</p>
</div>
</div>
<div class="div1">
<strong>
<p>Do not select me </p>
</strong>
<div class="div2">
<p>Select me only with css </p>
</div>
</div>
&#13;
gulp-octo
&#13;
答案 2 :(得分:1)
使用通用兄弟组合器~
.div1 strong ~ .div2 p {
color: red;
font-weight: bold;
}
&#13;
<div class="div1">
<div class="div2">
<p>Dont not select me</p>
</div>
</div>
<div class="div1">
<strong>
<p>Do not select me </p>
</strong>
<div class="div2">
<p>Select me only with css </p>
</div>
</div>
&#13;
答案 3 :(得分:1)