首頁  >  文章  >  web前端  >  使用 CSS 為作為其父級的第二個子級的每個元素設定樣式

使用 CSS 為作為其父級的第二個子級的每個元素設定樣式

WBOY
WBOY轉載
2023-09-11 08:57:08640瀏覽

使用 CSS 为作为其父级的第二个子级的每个元素设置样式

要使用CSS 為作為其父級的第二個子級的每個

元素設定樣式,請使用CSS :nth-child(n) 選擇器。

範例 h2>

您可以嘗試執行以下程式碼來實作:nth-child(n)選擇器

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-child(4) {
            background: orange;
            color: white;
         }
      </style>
   </head>
   <body>
      <p>This is demo text 1.</p>
      <p>This is demo text 2.</p>
      <p>This is demo text 3.</p>
      <p>This is demo text 4.</p>
      <p>This is demo text 5.</p>
      <p>This is demo text 6.</p>
   </body>
</html>

以上是使用 CSS 為作為其父級的第二個子級的每個元素設定樣式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除