使用CSS,当文本有文本装饰:下划线应用时,是否可以增加文本和下划线之间的距离?
当前回答
如果你想:
多行 虚线 自定义底部填充 没有包装
下划线,你可以使用1像素高度的背景图像重复x和100% 100%的位置:
display: inline;
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAAEUlEQVQIW2M0Lvz//2w/IyMAFJoEAis2CPEAAAAASUVORK5CYII=') repeat-x 100% 100%;
你可以用px或em之类的东西替换第二个100%来调整下划线的垂直位置。如果你想添加垂直填充,你也可以使用calc,例如:
padding-bottom: 5px;
background-position-y: calc(100% - 5px);
当然,你也可以用另一种颜色、高度和设计制作你自己的base64 png图案,例如:http://www.patternify.com/ -只需设置正方形宽度和高度为2x1。
灵感来源:http://alistapart.com/article/customunderlines
其他回答
不,但是你可以使用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-decoration: underline;
text-underline-offset: 3px;
Text-underline-offset是CSS自己的方法。 这里有更多关于text-underline-offset的内容
看我的小提琴。
你需要使用border width属性和padding属性。我添加了一些动画,让它看起来更酷:
身体{ background - color: lightgreen; } 一个{ 文字修饰:没有; 颜色:绿色; 边框样式:固体; 边框宽度:0px 0px 1px 0px; 过渡:所有。2s轻松; } 答:{徘徊 颜色:darkblue; 边框样式:固体; 边框宽度:0px 0px 1px 0px; 填充:2 px; } <a href='#' >某处…在彩虹之上(lalala)</a>,蓝色的鸟儿,飞…(推特推特!),我想知道(嗯)什么a < I ><a href="#">多么美妙的世界!< / >世界!< / i >
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