CSS 为什么 content span:after {content: ' '} 放在 span 内而不是 after?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28539951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:59:44  来源:igfitidea点击:

Why content span:after {content: ' '} is put inside span and not after?

csspseudo-element

提问by MDC

Why this CSS ...

为什么这个 CSS ...

.sticky-info span:after {content: 'test';}

... results in ...

... 结果是 ...

<div class="sticky-info"><span>Price <strong>&euro;120</strong>::after</span>

Is there a way to get the content:'test'behind every </span>inside <div class="sticky-info">There are several spans inside <div class="sticky-info">

有没有办法让content:'test'后面的每一个</span>里面<div class="sticky-info">有几个跨度<div class="sticky-info">

回答by Rudi

You can do it like this:

你可以这样做:

<div class="sticky-info">
    <span>Price <strong>&euro;120</strong></span>
</div>

CSS:

CSS:

.sticky-info:after {content: 'test';}

回答by MDC

::beforeand ::aftermeans before/after the CONTENT of the element so it's not possible in this way. Thx @Paulie_D and @Tim S.

::before并且::after表示在元素的 CONTENT 之前/之后,因此不可能以这种方式进行。谢谢@Paulie_D 和@Tim S。

回答by Sirence

http://fiddle.jshell.net/9g8qzt3f/

http://fiddle.jshell.net/9g8qzt3f/

If you use span::after the after will be added to the span, behind its content. To get it behind the span, use

如果使用 span::after ,则 after 将添加到 span,其内容后面。要让它落后于跨度,请使用

 .sticky-info:after {content: 'test';}