简体   繁体   English

如何在CSS中为下划线和上划线设置不同的颜色?

[英]How to have different color for underline and overline in css?

I have this currently 我现在有这个

 p { text-decoration: underline overline red; } 
 <p> This is some text </p> 

Here, I want to have different colors for the overline and underline . 在这里,我想为上overlineunderline设置不同的颜色。

Is this possible at all? 这有可能吗?

Put one span inside p and then you can set different color on span's overline . 将一个span放在p ,然后可以在跨度的上overline上设置不同的颜色。

 p { text-decoration: blue underline ; } span { text-decoration: red overline; } 
 <p><span>This is some text Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiis ut iusto optio, similique iure. Autem facilis, eveniet vel ea mollitia ad obcaecati dignissimos nisi, reiciendis odio voluptas, aliquid iure voluptatibus.</span></p> 

As far as I know you are only able to set text-decoration-color once and all decorations will have the same color. 据我所知,你只能设置一次text-decoration-color ,所有装饰都会有相同的颜色。 The syntax you are using as well will only work in Firefox currently. 您正在使用的语法目前仅适用于Firefox。 Other browsers will require prefixes like -webkit and may require experimental features be enabled in the browser. 其他浏览器需要像-webkit这样的前缀,并且可能需要在浏览器中启用实验性功能。

A far more universally compatible solution would be to apply a border to your text. 一个更普遍兼容的解决方案是在文本中应用边框。 You will be able to achieve the effect you want and it will be compatible everywhere. 你将能够达到你想要的效果,它将在任何地方兼容。

 p { border-top: 1px solid blue; border-bottom: 1px solid red; display: inline-block; } 
 <p>Testing</p> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM