Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3: font family within a glyphicon span

In Twitter Bootstrap 3, given this glyphicon span:

<span class="glyphicon glyphicon-home">&nbsp;Home</span>

the word 'Home' is rendered in standard sans serif instead of the font of the parent tag.

How can I assign an arbitrary font family to the text inside the span, and still render the icon correctly?

Of course I could move the text outside of the span, but then the &nbsp; would not be honored, would it? Regardless, from a semantic standpoint it would seem reasonable to keep the text described by the icon inside the span.

Here's an example:

enter image description here

That's how Chrome renders the following:

<h1>
<span class="glyphicon glyphicon-check"></span>&nbsp;Scoring
<span class="glyphicon glyphicon-home"> Home</span>
</h1>

The first span is how I want it to look, but is semantically wrong (IMOHO), while the second looks just wrong.

like image 315
Giuseppe Avatar asked Aug 30 '13 06:08

Giuseppe


People also ask

How do I reduce the size of a Glyphicon?

If you need to change the size of glyphicons, use the CSS font-size property.

Is bootstrap a Glyphicon?

Bootstrap provides set of graphic icons, symbols and fonts called Glyphicons. Some Glyphicons like Home icon, User icon, Lock icon, etc. Generally, Glyphicons are icon fonts which you can use in your web projects. Bootstrap includes 260 glyphicons.

Does bootstrap 4 have Glyphicons?

Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons.

Does bootstrap 5 support Glyphicons?

Bootstrap includes 260 glyphs from the Glyphicon Halflings set. Glyphicons Halflings are normally not available for free, but their creator has made them available for Bootstrap free of cost.


1 Answers

Since the icons are inserted using the :before pseudo-element you can make it so that the glyphicon font only applies to that instead of the actual element:

.glyphicon {
    font-family: inherit;
}
.glyphicon:before{
    font-family:'Glyphicons Halflings';
}

Demo fiddle

like image 92
omma2289 Avatar answered Sep 28 '22 03:09

omma2289