LLwanran / front_end_studying

前端知识要点
https://llwanran.github.io/front_end_studying/
2 stars 1 forks source link

:before/::before 和 :after/::after 区别?(上海海风教育1面) #11

Open LLwanran opened 5 years ago

LLwanran commented 5 years ago

单冒号(:)用于CSS3伪类

双冒号(::)用于CSS3伪元素

::before 就是以一个子元素的存在,定义在元素主体内容之前的一个伪元素。并不存在于dom之中,只存在于页面之中 :before:after 这两个伪元素,是在 CSS2.1 里新出现的。起初,伪元素的前缀使用的是单冒号语法,但随着Web的进化,在CSS3的规范里,伪元素的语法被修改成使用双冒号,成为 ::before ::after

标准写法是双冒号(但考虑兼容性也有人写单冒号)

常见伪元素:::before::after::first-line::first-letter::selection::placeholder

常见伪类::hover:link:active:target:not():focus