简单区分`:before`与`::before`的区别

简单区分:before::before的区别


:hover我们都知道,称作伪类,英文名pseudo-class,而我们此处提到的:before以及:after也是伪类,属于css2的内容,在ie8下也能正常的支持


至于::before,引用MDN的解释

::before creates a pseudo-element that is the first child of the element matched. It is often used to add cosmetic content to an element by using the content property. This element is inline by default.

也就是说,::before是伪元素pseudo-element而不是伪类

The ::before notation (with two colons) was introduced in CSS3 in order to establish a discrimination between pseudo-classes and pseudo-elements. Browsers also accept the notation :before introduced in CSS 2.

::before是属于css3的内容,之所以引入该属性,是为了与:before区分开,::before在ie8下不支持,其余的浏览器均支持该属性

外国友人以及国内大牛都很喜欢使用这两个属性,毕竟可以省写一个标签,同时为了兼容性考虑的话,尽量使用css2的:before

原文地址:https://www.cnblogs.com/jelly7723/p/5602349.html