试图找到一个以 <div>
为目标的伪类像这样:
<div class="nav-previous">
</div>
我试过了 :blank
和 :empty
但都无法检测到它。这是不可能的吗?
最佳答案
:empty
一个就够了。
通过 the current Selectors Level 4 specification , :empty
可以匹配仅包含文本节点且仅包含空白 以及完全为空的元素。只是根据当前规范,支持它的人并不多。
The
:empty
pseudo-class represents an element that has no children except, optionally, document white space characters.
来自 the MDN :
Note: In Selectors Level 4, the
:empty
pseudo-class was changed to act like:-moz-only-whitespace
, but no browser currently supports this yet.
The
:-moz-only-whitespace
CSS pseudo-class matches elements that only contain text nodes that only contain whitespace. (This includes elements with empty text nodes and elements with no child nodes.)
关于css - :empty doesn't work if there's blank spaces?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49368653/