• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • :empty

    版本:CSS3

    CSS 伪类:empty代表没有子元素的元素。子元素只可以是元素节点或文本(包括空格)。注释或处理指令都不会产生影响。

    语法:

    E:empty{sRules}

    匹配没有任何子元素(包括text节点)的元素E。

    :emptyCSS伪类代表没有子元素的元素。子元素只可以是元素节点或文本(包括空格)。注释或处理指令都不会产生影响。

    /* selects any <div> that contains no content */
    div:empty {
      background: lime;
    }
    

    浏览器支持

    IE9+以及新版浏览器都支持:empty

    例子

    //HTML
    
    <div class="box"><!-- i will be lime --></div>
    <div class="box">i will be pink</div>
    <div class="box">
        <!-- i will be red because of the whitespace around this comment -->
    </div>
    
    
    //CSS
    
    .box {
        background: pink;
        height: 80px;
        width: 80px;
    }
    
    .box:empty {
        background: lime;
    }
    
    i will be pink
    
    <style>
    p:empty
    {
    width:100px;
    height:100px;
    background:pink;
    }
    </style>
    
    
    <p></p>
    <p>指定空的元素的背景色</p>
    
    

    指定空的元素的背景色

    上篇::nth-last-of-type()

    下篇::target