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
Two ::after pseudo-elements
提问by JellicleCat
Possible Duplicate:
Adding pseudo-elements after pseudo-elements
可能的重复:
在伪元素之后添加伪元素
I'd like to apply two css ::after
pseudo-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 ::after
pseudo-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 ::after
pseudo-elements together so that one ::after
pertains 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 :before
pseudo-element in addition to your :after
- http://jsfiddle.net/BePSq/
:before
除了您的:after
- http://jsfiddle.net/BePSq/之外,您还可以使用伪元素
回答by bookcasey
You can't add two ::after
pseudo-elements to one DOM element. You can however add an ::before
additionally. 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 之后。但是,您只能使用这两个,并且不能添加更多的伪元素。