HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
💌
JJong’s Archive
/
구조 의사 클래스

구조 의사 클래스

Tags
CSS
HTML
Study Date
Nov 1, 2023
Status
Done
생성 일시
Nov 1, 2023 09:02 AM
Day

구조 의사 클래스(structural pseudo-class)

구조 의사 클래스를 사용하면 HTML 요소의 계층 구조에서 특정 위치에 있는 요소를 선택할 수 있습니다.
CSS에서 사용할 수 있는 구조 의사 클래스
(elem은 어떤 요소의 자식 요소임)
  • elem:first-child / elem:last-child : 자식 요소 중 맨 앞/뒤에 있는 elem
  • elem:nth-child(n) / elem:nth-last-child(n) : 자식 요소 중 앞/뒤에서부터 n번째에 위치하는 elem
  • elem:first-of-type / elem:last-of-type : elem 중에 첫번째
  • elem:only-child : elem이 유일한 자식일 때 해당 elem
  • elem:empty : 자식이 없는 elem(textarea도 있으면 안됨)
  • :root : 문서의 root 엘리먼트 반환
 

  • elem:first-child Vs elem:first-of-type
    • ⇒ elem:first-child : elem이 첫번째 자식이 아니라면 null
      elem:first-of-type : elem 중에 첫번째이므로, elem이 첫번째 자식이 아니어도 됨