首頁  >  文章  >  web前端  >  CSS 中 :first-child 偽類的用法

CSS 中 :first-child 偽類的用法

WBOY
WBOY轉載
2023-09-05 10:49:021226瀏覽

CSS 中 :first-child 伪类的用法

使用 :first-child 伪类向作为其他元素的第一个子元素的元素添加特殊样式。

示例

您可以尝试运行以下代码来了解 :first-child 伪类的用法 -

<html>
   <head>
      <style>
         div > p:first-child
         {
            text-indent: 25px;
         }
      </style>
   </head>
   <body>
      <div>
         <p>First paragraph in div. This paragraph will be indented</p>
         <p>Second paragraph in div. This paragraph will not be indented</p>
      </div>
         <p>But it will not match the paragraph in this HTML:</p>
      <div>
         <h3>Heading</h3>
         <p>The first paragraph inside the div. This paragraph will not be effected.</p>
      </div>
   </body>
</html>

以上是CSS 中 :first-child 偽類的用法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

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