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

前端之家收集整理的这篇文章主要介绍了css – 空白和空伪类之间的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有什么区别:empty和:blank(CSS Selectors Level 4 draft)?
除了空白仅适用于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 07002 [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>
原文链接:https://www.f2er.com/css/217748.html

猜你在找的CSS相关文章