:before 和 ::before 有什么区别?

发布于 2024-12-03 01:25:19 字数 231 浏览 0 评论 0原文

我刚刚看到一个包含 ::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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

渡你暖光 2024-12-10 01:25:19

根据这些文档,它们是等效的:

element:before  { style properties }  /* CSS2 syntax */

element::before { style properties }  /* CSS3 syntax */

唯一的区别是 CSS3 中使用双冒号,而单冒号是旧版本。

推理:

CSS 3 中引入了 ::before 表示法,以便建立一个
伪类和伪元素之间的区别。浏览器
还接受 CSS 2 中引入的符号 :before。

According to those docs, they are equivalent:

element:before  { style properties }  /* CSS2 syntax */

element::before { style properties }  /* CSS3 syntax */

The only difference is that the double colon is used in CSS3, whereas the single colon is the legacy version.

Reasoning:

The ::before notation was introduced in CSS 3 in order to establish a
discrimination between pseudo-classes and pseudo-elements. Browsers
also accept the notation :before introduced in CSS 2.

哆兒滾 2024-12-10 01:25:19

这将伪元素与伪类区分开来。

伪类和伪元素之间的区别在 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

独自唱情﹋歌 2024-12-10 01:25:19

它们本质上意味着同一件事。 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).

百变从容 2024-12-10 01:25:19

我查看了 MDNw3.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.

古镇旧梦 2024-12-10 01:25:19

一种是 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文