[英]Get the last element in HTML structure
Can I access the last div with the + content only with css & child combinators?我可以仅使用 css & 子组合器访问带有 + 内容的最后一个 div 吗? I would like to style it.
我想给它定型。
<body>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
+
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
with:last child i can't reach so deep into the tree. with:last child 我够不到树那么深。
The selector div:(not(:has(div))
will match any DIV that doesn't have another DIV nested inside it.选择器
div:(not(:has(div))
将匹配任何没有嵌套另一个 DIV 的 DIV。
:has(selector)
matches an element whose contents include an element that matches selector
. :has(selector)
匹配一个元素,该元素的内容包括一个与selector
匹配的元素。 Putting this in :not()
reverses the condition.把它放在
:not()
中可以逆转这种情况。
This is a relatively new CSS selector, and it's not yet supported by Firefox as of version 108. See the compatibility table .这是一个相对较新的 CSS 选择器,从版本 108 开始,Firefox 尚不支持它。请参阅兼容性表。
div:not(:has(div)) { color: red; }
<body> a <div> b <div> c <div> d <div> e <div> f <div> g <div> h <div> i <div> j <div> + </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.