과거에 ::before
사용시 콜론:
을 하나만 입력하여 :before
로 작성했었는데, 어느날부터 콜론을 두개씩 입력하기 시작했다. 이유가 뭘까?
This :: notation is introduced by the current document in order to establish a discrimination between pseudo-classes and pseudo-elements. For compatibility with existing style sheets, user agents must also accept the previous one-colon notation for pseudo-elements introduced in CSS levels 1 and 2 (namely, :first-line, :first-letter, :before and :after). This compatibility is not allowed for the new pseudo-elements introduced in this specification. -W3C
위와 같이 W3C 문서를 살펴보면 알 수 있듯, 이중 콜론::
은 의사 요소와 의사 클래스를 구분하기 위해 새롭게 도입된 문법이라고 적혀있다. 그렇다면, 의사 요소와 의사 클래스를 구분하는 이유가 뭘까? 각자 어떤 역할을 하고 있을까?
:
을 하나만 사용하는 :hover
, :active
, :focus
등과 콜론을 두개 사용하는 ::before
와 ::after
는 서로 역할이 다름