Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending an underline in CSS

Is it possible to over extend and underline so that it goes further than the word itself?

Like so:

enter image description here

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?

like image 679
SaturnsEye Avatar asked Feb 12 '14 10:02

SaturnsEye


People also ask

How do I extend an underline in CSS?

You need to put a border-bottom and extend the width of the p where the text exists. Hope this helps. Show activity on this post. I only want the line for top number, is it possible to use your example but set a p class to just the top number?

How do you make an underline longer?

Press and hold this keyboard shortcut combination to add multiple underlines next to each other, creating an underline. For example, holding down Ctrl + Shift and pressing the Spacebar five times would create an underline five characters long.

How do you customize underline in CSS?

Steps: Create background image with linear-gradient() . Adjust its size with css background-size property. Place it at the bottom left position of the element with background-position css property.

How do I control an underline in CSS?

In the horizontal text we use text-underline-position: under; to put the underline below all the descenders. In the text with a vertical writing-mode set, we can then use values of left or right to make the underline appear on the left or right of the text as required.


3 Answers

You can use content property with :after pseudo, if you do not want to use this, than you need to feed   on each u tag

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

Demo

Info: What's 00a0 here? 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..)


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. so support shouldn't matter much.

like image 120
Mr. Alien Avatar answered Sep 19 '22 17:09

Mr. Alien


No. You need to put a border-bottom and extend the width of the p where the text exists.

WORKING DEMO

The HTML:

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

The CSS:

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

Hope this helps.

like image 37
Nitesh Avatar answered Sep 19 '22 17:09

Nitesh


Use a border rather than underlining. Use the first-child pseudo class to apply it to only the first paragraph within .numbers:

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

JSFiddle

like image 22
George Avatar answered Sep 21 '22 17:09

George