CSS 两个 ::after 伪元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10855890/
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 04:04:43  来源:igfitidea点击:

Two ::after pseudo-elements

csspseudo-element

提问by JellicleCat

Possible Duplicate:
Adding pseudo-elements after pseudo-elements

可能的重复:
在伪元素之后添加伪元素

I'd like to apply two css ::afterpseudo-elements to a single DOM element, each with a different colour. (Yes, I could wrap the DOM element in another DOM element and give each one and ::afterpseudo-element, but my preference is cleaner html.)

我想将两个 css::after伪元素应用于单个 DOM 元素,每个元素都有不同的颜色。(是的,我可以将 DOM 元素包装在另一个 DOM 元素中,并赋予每个::after元素和伪元素,但我更喜欢更简洁的 html。)

I doubt it's possible, but wonder if someone can tell me better.

我怀疑这是可能的,但想知道是否有人能更好地告诉我。

I especially doubt the possibility of chaining ::afterpseudo-elements together so that one ::afterpertains to another, which pertains to a DOM element, but if anyone knows how to make that happen, please do tell.

我特别怀疑将::after伪元素链接在一起的可能性,以便一个::after属于另一个属于 DOM 元素的,但如果有人知道如何做到这一点,请告诉。

回答by Zoltan Toth

You can use a :beforepseudo-element in addition to your :after- http://jsfiddle.net/BePSq/

:before除了您的:after- http://jsfiddle.net/BePSq/之外,您还可以使用伪元素

回答by bookcasey

You can't add two ::afterpseudo-elements to one DOM element. You can however add an ::beforeadditionally. Depending on what you are trying to accomplish, this may work.

您不能::after向一个 DOM 元素添加两个伪元素。但是,您可以另外添加一个::before。根据您要完成的任务,这可能会奏效。

回答by David

You can use both the :before and :after pseudo-elements simultaneously on one DOM element. Just make sure you position them correctly. I believe :before places the psudo-element before the parent one, while :after places it after in the html. You can only use these two however and cannot add more pseudo-elements than that.

您可以在一个 DOM 元素上同时使用 :before 和 :after 伪元素。只要确保正确放置它们即可。我相信 :before 将伪元素放在父元素之前,而 :after 将它放在 html 之后。但是,您只能使用这两个,并且不能添加更多的伪元素。