伪元素的元素类型是什么? [英] What is the element type of pseudo-elements?

查看:250
本文介绍了伪元素的元素类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< pseudo> < / pseudo>

CSS的伪元素不在DOM中。但在内部,它们必须等同于某种类型的通用HTML元素,因为它们可以是样式化的,可见的,并且它们影响页面流。

The pseudo-elements of CSS are not in the DOM. But internally they must be equivalent to some kind of generic HTML element, since they can be styled, can be visible, and they affect the page flow.

什么是元素类型的伪元素?

What is the element type of a pseudo element?

我们可以通过编程方式创建它们,而不使用CSS?

推荐答案

伪元素没有元素类型,就文档语言而言,因为,如你所说,它们不存在于DOM中,并且可以从伪前缀,它们不是真实元素。 CSS只是调用它们的伪元素,但是你有不同的伪元素用于不同的目的或不同的元素结构的部分,如不说明 :: first-letter :: first-line :: before :: after 用于在元素的实际内容之前和之后生成内容。

Pseudo-elements have no element type as far as the document language is concerned because, as you state, they don't exist in the DOM, and as can be inferred from the "pseudo-" prefix, they're not "real" elements. CSS just calls them pseudo-elements, however you have different pseudo-elements for different purposes or different parts of element structures, such as the self-explanatory ::first-letter and ::first-line, and ::before and ::after for generating content before and after an element's actual content.

伪元素影响页面流与DOM无关。浏览器使用CSS来将DOM元素布局和格式化为可以呈现到屏幕的对象,并且在这样做的过程中,创建伪元素作为对于真实元素做出的框的后代。虽然通常将伪元素附加到元素,但您不会以任何方式更改DOM;

That pseudo-elements affect the page flow has nothing to do with the DOM. A browser uses CSS to lay out and format DOM elements into objects that can be rendered to the screen, and in the process of doing so creates pseudo-elements as descendants of boxes that are made for real elements. Although you typically attach a pseudo-element to an element, you're not altering the DOM in any way; instead, you're simply altering how the browser lays out a page.

因为伪元素是CSS独有的概念(定义在选择器模块),您不能使用CSS以外的任何其他模块创建它们。伪元素作为CSS概念的实现在 CSSOM 中定义,而CSS是等效的的DOM(并且定义了 window.getComputedStyle()等方法)。但是我不太熟悉CSSOM,所以我不能进一步评论,它们的实现非常类似于CSS的真实元素。

Because pseudo-elements are a concept unique to CSS (defined in the Selectors module), you cannot create them using anything other than CSS. The implementation of pseudo-elements as a CSS concept is defined in CSSOM instead, which is the CSS equivalent of the DOM (and where methods like window.getComputedStyle() are defined). However I'm not very familiar with the CSSOM, so I can't comment further than that they're implemented very similarly to real elements in terms of CSS.

这篇关于伪元素的元素类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆