選擇每個
    前面的元素

    元素 CSS


使用元素 ~ 元素選擇器選擇 <p> 元素前面的 <ul> 元素。你可以嘗試執行以下程式碼來實現此操作

示例

動態演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         p~ul {
            color: white;
            background-color: blue;
         }
      </style>
   </head>
   <body>
      <h1>Demo Website</h1>
      <h2>Fruits</h2>
      <div>
         <p>Vegetables are good for health.</p>
         <ul>
            <li>Spinach</li>
            <li>Onion</li>
            <li>Capsicum</li>
         </ul>
      </div>
      <p>Fruits are good for health.</p>
      <ul>
         <li>Apple</li>
         <li>Orange</li>
         <li>Kiwi</li>
      </ul>
   </body>
</html>

更新於:2020 年 6 月 24 日

2K+ 瀏覽量

開啟你的 職業

完成課程即可獲得認證

開始學習
廣告