简体   繁体   English

如何通过css显示多个下划线颜色(而不是一种颜色)

[英]How to display mutiple underline color by css (instead of one color)

I would like to display mutiple underline color to a certain text我想为某个文本显示多个下划线颜色

I know that text-decoration-color is to set underline color.我知道 text-decoration-color 是设置下划线颜色。

But I want to have sth like below但我想拥有像下面这样的东西

在此处输入图像描述

You can make a pseudo element by using :after您可以使用:after创建一个伪元素

 span { text-decoration: underline; text-decoration-color: red; text-decoration-thickness: 2px; position: relative; } span::after { content: ""; width: 100%; display: block; position: absolute; height: 4px; background: orange; bottom: -6px; border-radius: 10px; }
 <p> <span>Text-decoration</span> is to set underline color. </p>

This is a solution for having multiple borders using box-shadow and text-decoration at the same time.这是一种同时使用box-shadowtext-decoration来拥有多个边框的解决方案。 The regular border was added as the first underline crossing the font baseline with an offset defined by text-underline-offset常规边框被添加为与字体基线交叉的第一个下划线,其偏移量由text-underline-offset定义

 .paragraph{ font-size: 20px; font-family: arial; color: #2C019D; } .highlight{ box-shadow: 0px 2px white, 0px 10px orange; text-decoration: underline solid red 2px; text-underline-offset: 2px; }
 <span class="paragraph">I'd far rather be <span class="highlight">happy than right</span> any day</span>

Using outline and clip-path使用outlineclip-path

 span { text-decoration: underline; /* first underline */ outline: 5px solid orange; /* second underline */ outline-offset: 2px; /* control the gap */ clip-path: inset(0 0 -100vmax); } p { font-size: 30px; font-family: sans-serif; line-height: 1.4; }
 <p> <span>Happy than right</span> is to set underline color. </p>

Also with gradient to support multi-line of text:还带有渐变以支持多行文本:

 span { text-decoration: underline; background: linear-gradient(0deg,orange 5px,#0000 0); padding-bottom: 7px; /* control the gap */ } p { font-size: 30px; font-family: sans-serif; line-height: 1.4; }
 <p> <span>Happy than right is to set underline color with multiline of text</span> </p>

You may try to apply different span with different style您可以尝试应用不同风格的不同跨度

.doubleHightlight{
box-shadow:
    0px 2px yellow,    
    0px 10px orange;
}

.singleHightlight{
box-shadow:
    0px 2px yellow, 
}

You can surround text with a span and give it a border, like so:你可以用 span 包围文本并给它一个边框,如下所示:

<span>happy than right<span>
span {
    text-decoration: underline;
    text-decoration-color: red;
    border-bottom: 1px solid orange;
}

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

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