如何进行文本修饰:使用2px填充下划线?

NiL*_*iLL 17 html css

我喜欢一个听话的frotend开发人员必须使用2px填充而不是1px默认创建下划线.存在简单的解决方案吗?

PS Yeahh伙计们,我知道div有黑色背景颜色和1px*Npx和位置:相对,但它太慢了......

Jas*_*aro 33

你可以自动换行的span,并给它一个border-bottompadding-bottom:2px;.

像这样

span{
    display:inline-block;
    border-bottom:1px solid black;
    padding-bottom:2px;
}
Run Code Online (Sandbox Code Playgroud)

示例:http://jsfiddle.net/uSMGU/


Rus*_*kin 15

对于跨浏览最好是使用text-underline-offset过的text-underline-position,因为text-underline-position不支持iOS的Safari浏览器

所以使用这个答案:https : //stackoverflow.com/a/63607426/1894907

#line{
    text-decoration-line: underline;
    text-underline-offset: 2px;
}
Run Code Online (Sandbox Code Playgroud)


小智 11

在没有添加额外跨度和更多控制的情况下执行此操作的好方法是使用:after选择器.

特别适用于导航菜单:

.active a:after {
    content: '';
    height: 1px;
    background: black; 
    display:block;
}
Run Code Online (Sandbox Code Playgroud)

如果您希望文本和下划线之间有更多或更少的空间,请添加一个margin-top.

如果您想要更粗的下划线,请添加更多height:

.active a:after {
    content: '';
    height: 2px;
    background: black; 
    display:block;
    margin-top: 2px;
}
Run Code Online (Sandbox Code Playgroud)


小智 10

只需使用:

text-decoration: underline;
text-underline-position: under;
Run Code Online (Sandbox Code Playgroud)

图片


Ale*_*lex 6

如何使用 border-bottom:1px; padding:what-you-likepx


小智 6

#line{
    text-decoration-line: underline;
    text-underline-offset: 1px;
}
Run Code Online (Sandbox Code Playgroud)
<div id="line">
Text with line
</div>
Run Code Online (Sandbox Code Playgroud)


只是使用

{
    text-decoration-line: underline;
    text-underline-offset: 2px;
}
Run Code Online (Sandbox Code Playgroud)

  • 欢迎来到堆栈溢出。Stack Overflow 上不鼓励仅提供代码答案,因为它们没有解释它如何解决问题。请编辑您的答案以解释此代码的作用以及它如何改进此问题已经有的许多其他已投票答案,以便它对具有类似问题的其他用户有用。 (3认同)