Using CSS :before and :after pseudo-elements with inline CSS?(使用带有内联 CSS 的 CSS :before 和 :after 伪元素?)
问题描述
我正在使用内联 CSS(即 style
属性中的 CSS)制作 HTML 电子邮件签名,我很好奇是否可以使用 :before
和 :after
伪元素.
I'm making an HTML email signature with inline CSS (i.e. CSS in style
attributes), and I am curious as to whether it's possible to use the :before
and :after
pseudo-elements.
如果是这样,我将如何使用内联 CSS 实现类似的功能?
If so, how would I implement something like this with inline CSS?
td { text-align: justify; }
td:after { content: ""; display: inline-block; width: 100%; }
推荐答案
你不能为伪元素指定内联样式.
You can't specify inline styles for pseudo-elements.
这是因为伪元素,如伪类(请参阅我对 this其他问题),在 CSS 中定义,使用选择器作为不能用 HTML 表示的文档树的抽象.另一方面,内联 style
属性是在 HTML 中为特定元素指定的.
This is because pseudo-elements, like pseudo-classes (see my answer to this other question), are defined in CSS using selectors as abstractions of the document tree that can't be expressed in HTML. An inline style
attribute, on the other hand, is specified within HTML for a particular element.
由于内联样式只能出现在 HTML 中,它们只会应用于定义它们的 HTML 元素,而不适用于它生成的任何伪元素.
Since inline styles can only occur in HTML, they will only apply to the HTML element that they're defined on, and not to any pseudo-elements it generates.
顺便说一句,伪元素和伪类在这方面的主要区别在于默认继承的属性将被 :before
和 :after
继承生成元素,而伪类样式根本不适用.例如,在您的情况下,如果您将 text-align: justify
放在 td
元素的内联样式属性中,它将被 td:after 继承代码>.需要注意的是,您不能使用内联样式属性声明
td:after
;您必须在样式表中执行此操作.
As an aside, the main difference between pseudo-elements and pseudo-classes in this aspect is that properties that are inherited by default will be inherited by :before
and :after
from the generating element, whereas pseudo-class styles just don't apply at all. In your case, for example, if you place text-align: justify
in an inline style attribute for a td
element, it will be inherited by td:after
. The caveat is that you can't declare td:after
with the inline style attribute; you must do it in the stylesheet.
这篇关于使用带有内联 CSS 的 CSS :before 和 :after 伪元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用带有内联 CSS 的 CSS :before 和 :after 伪元素?


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01