简体   繁体   English

文字装饰颜色线性渐变

[英]Text decoration color linear gradient

please how do I set a linear-gradient to a text-decoration-color property in css.请问如何在 css 中将线性渐变设置为文本装饰颜色属性。 I've been trying to implement it but it's not working我一直在尝试实施它,但它不起作用

[what I actually wanted it to look like](https://i.stack.imgur.com/QDKhi.jpg)

 p{ background-image: linear-gradient(90deg,rgb(98,60,49)0,rgb(255,255,255) 100%); background-repeat: no-repeat; background-position-y: bottom; background-size:100% 15%; width:fit-content; }
 <p>This is text with a gradient decoration</p>

Something like this could work.这样的事情可以工作。 Backgrounds should be your friend in this situation.在这种情况下,背景应该是你的朋友。

The best way is a ::before or just a div to do the same effect.最好的方法是一个::before或只是一个div来达到同样的效果。 Ex:前任:

 .container { height: 100vh; display: flex; justify-content: center; align-items: center; } p { position: relative; font-size: 40px; } p::before { content: ""; position: absolute; top: 100%; width: 100%; left: 0; height: 5px; border-radius: 2px; background: linear-gradient(111.3deg, #9c27b0 9.6%, #00bcd4 93.6%); }
 <div class="container"> <p>I love CSS</p> </div>

Reference 参考

To set a linear gradient as the 'text-decoration-color' in CSS, you can use the 'linear-gradient()' function as the value of the 'text-decoration-color property'.要在 CSS 中将线性渐变设置为“text-decoration-color”,您可以使用“linear-gradient()”函数作为“text-decoration-color property”的值。

Here is an example of how you can do this:以下是如何执行此操作的示例:

a {
  text-decoration: none;
  text-decoration-color: linear-gradient(to right, #ff0000, #ffff00);
}

This will apply a linear gradient that goes from red to yellow as the text-decoration-color for all 'a' elements.这将应用从红色到黄色的线性渐变作为所有“a”元素的文本装饰颜色。

Please note that the 'text-decoration-color' property is not supported in all browsers, so you may need to use a vendor prefix for full cross-browser compatibility.请注意,并非所有浏览器都支持“text-decoration-color”属性,因此您可能需要使用供应商前缀以实现完全的跨浏览器兼容性。 Here is an example of how you can use vendor prefixes:以下是如何使用供应商前缀的示例:

a {
  text-decoration: none;
  -webkit-text-decoration-color: linear-gradient(to right, #ff0000, #ffff00);
  text-decoration-color: linear-gradient(to right, #ff0000, #ffff00);
}

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

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