css - 空白和空伪类之间的区别

标签 css css-selectors

:empty 和 :blank 之间有什么区别(CSS 选择器第 4 级草案)? 除了目前空白仅适用于 Firefox 的事实。

div div{
  
  width:100px;
  height:100px;
  display:inline-block;
  margin:5px;
  }
div.emptyCell:empty{
  
  background:#009688;
  
  }
div.blankCell:blank{
  
  background:#3F51B5;
  
  }
<div><div class="emptyCell"><!-- nothing but a comment--></div>
<div class="emptyCell"></div>
<div class="emptyCell"><!-- nothing but a comment--></div>
<div class="emptyCell"></div>
  </div>
<div>
<div class="blankCell"></div>
<div class="blankCell"><!-- nothing but a comment--></div>
<div class="blankCell"></div>
<div class="blankCell"><!-- nothing but a comment--></div>
  </div>

最佳答案

The :blank pseudo-class builds upon the :empty pseudo-class. Like :empty, :blank will select elements that contain nothing at all, or contain only an HTML comment. But, :blank will also select elements that include whitespace, which :empty will not.

css-tricks :blank

此外,From the W3c Working Draft on selectors level 4 :

The :blank pseudo-class is identical to the :empty pseudo-class, except that it additionally excludes characters affected by whitespace processing [CSS3TEXT] when determining whether an element is empty.

例子:

For example, the following element matches :blank, but not :empty, because it contains at least one linebreak, and possibly other whitespace:

<p> 
</p>

关于css - 空白和空伪类之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32580185/

相关文章:

html - 以 HTML 为中心获取对象,但可扩展以适应任何屏幕

html - 相对于同级水平定位元素而不包装 div

android - Jsoup : Select a row with class name containing whitespace at the end

python - 如何使用 Selenium 和 Python 选择具有不可选择的 ="on"属性的 kendo 下拉元素

css - 带有表格边框的 Chrome css 问题

html - 使用 CSS 为字体添加阴影效果

html - 看似多余的 CSS 选择器

javascript - 从 Dom 元素获取 CSS 路径

html - 在搜索栏旁边添加 "Advanced Search Button"

html - 我在这个 CSS 布局中做错了什么?