css - :empty doesn't work if there's blank spaces?

标签 css css-selectors pseudo-class

试图找到一个以 <div> 为目标的伪类像这样:

<div class="nav-previous">
                            </div>

我试过了 :blank:empty但都无法检测到它。这是不可能的吗?

https://jsfiddle.net/q3o1y74k/3/

最佳答案

: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/

相关文章:

css - CSS3 :hover and :focus? 之间的差异

jquery - ":first-of-type"有效,":last-of-type"无效

html - Google Chrome CSS 类伪类组不起作用

javascript - 如何在 Google Chrome 的 HTML 页面中管理多个 AJAX 调用的加载?

html - 背景颜色不覆盖 div 的全高

html - 如何在单个文本类上有多个悬停类

javascript - 测试选择器是否匹配给定元素

jquery - html - div 内的布局中断

CSS 未链接且无法与 Spring Boot 应用程序一起使用

css - 查看悬停元素的继承 CSS 属性