ホームページ  >  記事  >  ウェブフロントエンド  >  CSS での:first-child 疑似クラスの使用法

CSS での:first-child 疑似クラスの使用法

WBOY
WBOY転載
2023-09-05 10:49:021226ブラウズ

CSS 中 :first-child 伪类的用法

:first-child 疑似クラスを使用して、他の要素の最初の子である要素に特別なスタイルを追加します。

:first-child pseudo-class -

<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 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。