CSS선택자 nth-child / nth-of-type의 사용법과 차이점을 알아보자

nth-child와 nth-of-type의 사용법은 동일하다 하지만 결과물에서 차이점이 존재한다


결과는 과연?

결과값은 다르다

nth-child같은 경우 유형(태그)에 상관없이 순서를 확인하고 지정한 태그와 선택된 태그가 맞다면 결과를 출력한다
nth-of-type같은 경우 지정한 유형(태그)안에서 순서를 확인하고 결과를 출력한다

기타 사용법

child설명type
first-child첫번째 요소를 선택first-of-type
last-child마지막 요소를 선택last-of-type
nth-child(odd)홀수인 요소를 선택nth-of-type(odd)
nth-child(even)짝수인 요소를 선택nth-of-type(even)
nth-child(5)디섯번째 요소를 선택nth-of-type(5)
nth-child(2n+2)2의 배수인 요소 선택, but 2번째 요소부터nth-of-type(2n+2)
not(:nth-child(3))3번째 요소를 제외한 모든 요소 선택not(:last-of-type(2))
profile
미완성형 지성체

0개의 댓글

Powered by GraphCDN, the GraphQL CDN