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

CSS를 사용하여 부모의 첫 번째 자식인 모든

요소에 스타일 지정

<시간/>

부모의 첫 번째 자식인 모든

요소의 스타일을 지정하려면 CSS :first-child 선택기를 사용하세요.

예시

다음 코드를 실행하여 :first-child 선택기 −

를 구현할 수 있습니다.
<!DOCTYPE html>
<html>
   <head>
      <style>
         p:first-child {
            background-color: orange;
         }
      </style>
   </head>
   <body>
      <h1>Heading</h1>
      <p>This is demo text.</p>
      <div>
         <p>This is demo text, with the first child of its parent div.</p>
         <p>This is demo text, but not the first child.</p>
      </div>
   </body>
</html>