1. 程式人生 > 實用技巧 >:empty (Selectors) – CSS 中文開發手冊

:empty (Selectors) – CSS 中文開發手冊

[
  •   CSS 中文開發手冊

    :empty (Selectors) - CSS 中文開發手冊

    該:empty偽類代表沒有子節點的所有元素。這裡只考慮元素節點和文字(包括空格)。註釋或處理指令不影響元素是否被認為是空的。

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

    語法

    :empty

    例項

    body {
      display: flex;
      justify-content: space-around;
    }
    
    .box {
      background: red;
      height: 100px;
      width: 100px;
    }
    
    .box:empty {
      background: lime;
    }
    <div class="box"><!-- I will be lime --></div>
    <div class="box">I will be red</div>
    <div class="box">
        <!-- I will be red because of the whitespace around this comment -->
    </div>

    規範

    Specification

    Status

    Comment

    Selectors Level 4The definition of ':empty' in that specification.

    Working Draft

    No change

    Selectors Level 3The definition of ':empty' in that specification.

    Recommendation

    Initial definition

    瀏覽器相容性

    Feature

    Chrome

    Edge

    Firefox (Gecko)

    Internet Explorer

    Opera

    Safari

    Basic support

    1.0

    (Yes)

    1.0 (1.7 or earlier)

    9.0

    9.5

    3.1

    Feature

    Android

    Edge

    Firefox Mobile (Gecko)

    IE Mobile

    Opera Mobile

    Safari Mobile

    Basic support

    2.1

    (Yes)

    1.0 (1)

    9.5

    10.0

    3.1

  •   CSS 中文開發手冊
    ]
  •   本文標題::empty (Selectors) – CSS 中文開發手冊 - Break易站轉載請保留頁面地址:https://www.breakyizhan.com/css/31213.html