使用CSS,当文本有文本装饰:下划线应用时,是否可以增加文本和下划线之间的距离?


当前回答

Use

{
   text-decoration: underline;
   text-underline-offset: 2px;
}

Here, text-underline-offset: 2px;  is used to define the distance of the underline from the text, where "2px" is the distance.

Note: text-underline-offset: 2px;  can only be used after 
                  text-decoration: underline;

You can also change the thickness of underline by writing
                   text-decoration: underline 5px;
where "5px" is the thickness.
      

进一步查询请参考此链接:https://developer.mozilla.org/en-US/docs/Web/CSS/text-underline-offset

其他回答

我知道这是一个老问题,但对于单行文本设置显示:内联块,然后设置高度,这对我来说很好地控制了边框和文本之间的距离。

不,但是你可以使用border-bottom: 1px solid #000和padding-bottom: 3px。

如果你想要与“下划线”(在我的例子中是边框)相同的颜色,你只需省略颜色声明,即border-bottom-width: 1px和border-bottom-style: solid。

对于多行,您可以将多行文本包装在元素内的span中。例如,<a href="#"><span>插入多行文本在这里</span></a>然后添加border-bottom和padding在<span> - Demo

你可以使用:

text-underline-position: under;

text-underline-offset: {value(px)};

这个属性会根据你提供的offset值来移动链接下面的下划线。

如需更多参考资料,请访问: textunderlineoffest | developer.mozilla.org

我可以使用U(下划线标签)

u {
    text-decoration: none;
    position: relative;
}
u:after {
    content: '';
    width: 100%;
    position: absolute;
    left: 0;
    bottom: 1px;
    border-width: 0 0 1px;
    border-style: solid;
}


<a href="" style="text-decoration:none">
    <div style="text-align: right; color: Red;">
        <u> Shop Now</u>
    </div>
</a>

以下是对我很有效的方法。

<风格type = " text / css " > # underline-gap { 文字修饰:下划线; text-underline-position:下; } > < /风格 身体< > < h1 id = " underline-gap " > < a href = " https://Google.com " >谷歌< / > < / h1 > < /身体>