Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS에서 :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>