CSS 選擇器 :empty 的作用


使用 CSS :empty 選擇器,對沒有 CSS 子元素的所有 <p> 元素應用樣式。您可以嘗試執行以下程式碼來實現 :empty 選擇器 -

示例

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p.demo {
            width: 300px;
            height: 20px;
            background: gray;
          }
          p:empty {
             width: 150px;
             height: 20px;
             background: orange;
         }
      </style>
   </head>
   <body>
      <p class = "demo">This is demo text. Below is empty text.</p>
      <p></p>
   </body>
</html>

更新日期:30-Jun-2020

154 次瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始學習
廣告