Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Icons: Cannot remove top and bottom padding (font awesome)

Here is my fiddle:

http://jsfiddle.net/schmudde/VeA6B/

I cannot remove the top and bottom padding on either side of a font awesome icon:

span {
    border: 1px solid red;
    line-height: 40%;
}
i {
    border: 1px solid green;
    padding: 0px;
    margin: 0px;
    display: inline-block;
    width: auto;
    height: auto;
    line-height: inherit;
    vertical-align: baseline;
    background-color: red;
}

<span><i class="icon-check icon-3x"></i></span>

I have attempted specific line-heights and inheriting line-heights. There is something fundamental here I am clearly not understanding.

like image 960
Schmudde Avatar asked Apr 17 '14 00:04

Schmudde


People also ask

Why do Font Awesome icons not work?

Make sure you're using the latest and greatest by updating your CDN code reference, updating your Font Awesome package via npm, or downloading a fresh copy of Font Awesome. You can check with version an icon was added to on its detail page (e.g. question-circle was added in Verion 1 but last updated in 5.0. 0).

Is Font Awesome no longer free?

Font Awesome is fully open source and is GPL friendly. You can use it for commercial projects, open source projects, or really just about whatever you want.

Why Font Awesome icon is showing as a square?

Quoted from their website: The fa prefix has been deprecated in version 5. The new default is the fas solid style and the fab style for brands. This is why my fonts were showing blank squares.


2 Answers

Use span { line-height: 100%; } so it would fill the block.

like image 78
punund Avatar answered Sep 28 '22 03:09

punund


The line-height on the span won't help you much as the icon is added to the pseudo class :before on the <i /> tag. This pseudo class will create a somewhat hidden element, if you can call it that.

So if you want to override the css:

.icon-check:before { font-size: 2rem; }

Removing the padding of the icon can be tricky. Maybe if you set the span to display: inline-block you can use height, width in combination with overflow: hidden.

span {
    border: 1px solid #FF0000;
    display: inline-block;
    height: 38px;
    overflow: hidden;
    position: relative;
    width: 45px;
}
i.icon-check:before {
    left: 0;
    position: absolute;
    top: -4px;
}

DEMO

like image 24
Tim Vermaelen Avatar answered Sep 28 '22 02:09

Tim Vermaelen