>  기사  >  웹 프론트엔드  >  CSS에서 :first-child 의사 클래스 사용

CSS에서 :first-child 의사 클래스 사용

WBOY
WBOY앞으로
2023-09-05 10:49:021226검색

CSS 中 :first-child 伪类的用法

다른 요소의 첫 번째 자식인 요소에 특별한 스타일을 추가하려면 :first-child 의사 클래스를 사용하세요.

Example

다음 코드를 실행하여 :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으로 문의하시기 바랍니다. 삭제