프론트엔드 첫걸음

띄어쓰기 유무에 따라 달라지는 가상클래스 본문

개발 공부/CSS

띄어쓰기 유무에 따라 달라지는 가상클래스

차정 2022. 7. 2. 11:39

See the Pen 띄어쓰기 유무에 따라 달라지는 가상클래스 by JEONG (@cona) on CodePen.

 

  •  li:last-of-type
    • li의 부모 하위의 li 중 맨마지막 li
    • last-of-type인 list (마지막 list)
  • li :last-of-type
    • 띄어쓰기가 있는경우는 li의 하위 요소중에 본인과 같은 tag중 마지막을 선택
    • last-of-type인 list 하위요소
  • li:last-child
    • li의 부모요소의 마지막자식인데 이게 li일때만!
    • last-child인 li → 그런데 li가 last-child가 아니면 (tag종류 불문 맨 마지막 요소가 아니면) 선택안됨!
  • li :last-child
    • li 내부의 요소들 중에서 마지막 자식

 

https://stackoverflow.com/questions/18995362/last-child-not-working-as-expected

 

:last-child not working as expected?

The issue lies within this CSS and HTML. Here is a link to jsFiddle with the sample code. HTML <ul> <li class"complete">1</li> <li class"complete">2</li> ...

stackoverflow.com

 

See the Pen last-child by JEONG (@cona) on CodePen.