Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix gap that appears on an LI element when using :after

Tags:

html

css

Please take a look at this fiddle http://jsfiddle.net/EWUTX/

These are the styles used:

.box { position: relative; display:inline-block;}
.box:after {
    position: absolute;
    width: 100%;
    height: 10px;
    background: green;
    content: '';
    bottom:-10px;
    left:0;
}

I get a small 5px gap when using the style on an li element, but not on a div tag.

If I specify font-size: 0px, the gap goes away. But then all the text within the li disappears.

As the font size of the li increases, the gap widens.

Is there a style to get rid of this gap, without any hard coding of font sizes?

Fiddle again: http://jsfiddle.net/EWUTX/

Thanks

PS: I'm actually building a CSS framework internally where users can specify a status (using classes) like "started", "not-started", etc.

When used, the element should display a small bar below with different colors. Users can use this class on any element.

like image 750
Arun Avatar asked Aug 21 '13 14:08

Arun


2 Answers

That gap is part of the line height reserved characters like 'p' letter. You will get the same gap if you don't set a height to your div. If you want to remove that from an inline element like an img you can set the vertical-align to the bottom:

.box img {
    vertical-align: bottom;
}

See: http://jsfiddle.net/DhTzp/

like image 135
Esteban Avatar answered Oct 03 '22 06:10

Esteban


Its the image that crates the whitespace;

img{ display: block; }
like image 42
Razz Avatar answered Oct 03 '22 07:10

Razz