:before 和 ::before 有什么区别?
我刚刚看到一个包含 ::before
标签的 CSS 代码。我查看了 MDN 以了解 ::before
是但我真的不明白。
有人可以解释它是如何工作的吗?
它会在我们通过 CSS 选择元素之前创建 DOM 元素吗?
I just saw a CSS code that included ::before
tag. I looked at MDN to see what the ::before
is but I really didn't understand it.
Can someone explain how it works?
Does it make a DOM element before what we select by CSS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据这些文档,它们是等效的:
唯一的区别是 CSS3 中使用双冒号,而单冒号是旧版本。
推理:
According to those docs, they are equivalent:
The only difference is that the double colon is used in CSS3, whereas the single colon is the legacy version.
Reasoning:
这将伪元素与伪类区分开来。
伪类和伪元素之间的区别在 http://www 中描述.d.umn.edu/~lcarlson/csswork/selectors/pseudo_dif.html
This distinguishes pseudo elements from pseudo classes.
The difference between pseudo classes and pseudo elements is described at http://www.d.umn.edu/~lcarlson/csswork/selectors/pseudo_dif.html
它们本质上意味着同一件事。 CSS3 中引入了
::
来帮助区分伪元素(如 :before 和 :after)和伪类(如 :link 和 :hover)。They essentially mean the same thing. The
::
was introduced in CSS3 to help descriminate between pseudo elements (like :before and :after) and pseudo classes (like :link and :hover).我查看了 MDN 和 w3.org,我能想到的最好的办法是
::
用于结构< /strong> 改变,以及:
用于样式。出于兼容性原因,它们目前可以互换。
它似乎将
:link
(例如)(它的样式为)与
:before
(这是一个 结构变化)。:
用于样式,::
用于结构。I checked out MDN and w3.org, and the best I could come up with is that
::
is used for structural changes, and:
is used for styling.They are currently interchangeable for compatibility reasons.
It appears to separate
:link
(for instance), which styles a<a>
, from:before
(which is a structural change).:
is for styling,::
is for structure.一种是 CSS2 (:before) 方式,另一种是 CSS3 (::before) 方式。目前,它们在支持 CSS2 和 CSS2 的浏览器中是可以互换的。 CSS3。
这是一个很好的解释: http://www.impressivewebs.com/before-after-css3/< /a>
One is the CSS2 (:before) way and the other is CSS3 (::before). Currently they are interchangeable in browsers that support CSS2 & CSS3.
Here's a good explanation: http://www.impressivewebs.com/before-after-css3/