简体   繁体   English

在CSS中扩展下划线

[英]Extending an underline in CSS

Is it possible to over extend and underline so that it goes further than the word itself? 是否有可能过度延伸和下划线,以便它比单词本身更进一步?

Like so: 像这样:

在此输入图像描述

I tried: 我试过了:

.numbers u {
    width:200px;
}

FIDDLE 小提琴

I was hoping it would work but I got nothing. 我希望它会起作用,但我一无所获。

Is there some sort of css trick to make this possible? 是否有某种css技巧可以实现这一目标?

You can use content property with :after pseudo, if you do not want to use this, than you need to feed   你可以使用content属性:after伪,如果你不想使用它,那么你需要提供  on each u tag 在每个u标签上

.numbers u:after {
    content: "\00a0\00a0\00a0\00a0";
}

Demo 演示

Info: What's 00a0 here? 信息:这是什么00a0? It's a Non Break Space 这是一个非休息空间

Can also use something like 也可以使用类似的东西

.numbers u:after {
    content: "................";
    color: transparent;
}

Demo 2 (But I would prefer \\00a0 one..) 演示2 (但我更喜欢\\00a0一个..)


As far as browser support goes, content as well as :after are supported in IE8, Side note, ::after is supported in IE9 but using :after is just fine here. 至于浏览器支持, content以及:after在IE8中支持,Side note, ::after在IE9中支持但使用:after就好了。 so support shouldn't matter much. 所以支持不应该太重要。

No. You need to put a border-bottom and extend the width of the p where the text exists. 不需要。您需要设置border-bottom并扩展文本所在的p的宽度。

WORKING DEMO 工作演示

The HTML: HTML:

<p class="underline">One</p>

The CSS: CSS:

.underline{border-bottom:1px solid #000000; width:200px; padding-bottom:5px;}

Hope this helps. 希望这可以帮助。

Use a border rather than underlining. 使用边框而不是下划线。 Use the first-child pseudo class to apply it to only the first paragraph within .numbers : 使用first-child伪类将其仅应用于.numbers的第一个段落:

.numbers p:first-child {
    width:200px;
    border-bottom:1px solid #000;
    padding-bottom:1px;
}

JSFiddle 的jsfiddle

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

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