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

CSS의 역할 :nth-of-type(n) 선택기

<시간/>

CSS :nth-of-type(n) 선택기를 사용하여 부모의 n번째

요소인 모든

요소의 스타일을 지정합니다. 다음 코드를 실행하여 :nth-of-type(n) 선택기를 구현할 수 있습니다.

예시

<!DOCTYPE html>
<html>
   <head>
      <style>
         p:nth-of-type(2) {
            background: yellow;
         }
      </style>
   </head>
   <body>
      <p>This is demo text 1.</p>
      <p>This is demo text 2.</p>
      <p>This is demo text 3.</p>
      <p>This is demo text 4.</p>
   </body>
</html>