Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give font-awesomes icon a fixed width?

I am using Bootstrap and Font Awesome to make a table like the one from FAQ zalando.

So on the left side, there should be an icon, and on the right side, there should be text.

I want the text to be exactly under each other, they should not be out of alignment with each other. If I give the icons a span, then it will be ignored.

Here is my code:

<div class="row">
    <i class="span2 icon-user "></i>
    <div value='register' class="span4">
        Registrierung
    </div>
    <i class="icon-mobile-phone span2"></i>
    <div id='Newsletter' class="span4">
        Newsletter
    </div>
</div>
<div class="row">
    <i class="icon-euro span2"></i>
    <div value='kost' class="span4">
        Kosten
    </div>

    <i class="icon-phone span2"></i>
    <div id='probleme' class="span4">
        Probleme
    </div>
</div>
like image 291
Brigitte Fellner Avatar asked Aug 30 '13 14:08

Brigitte Fellner


People also ask

How do I change the width of font awesome icons?

To increase icon sizes relative to their container, use the fa-lg (33% increase), fa-2x , fa-3x , fa-4x , or fa-5x classes. If your icons are getting chopped off on top and bottom, make sure you have sufficient line-height.

How do I fix font awesome?

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.


3 Answers

As an update to this, FontAwesome now has fixed-width support built in.

<i class="fa fa-fw fa-user"></i>

The fa-fw class supplies the fixed-width style.

like image 134
mwotton Avatar answered Nov 05 '22 23:11

mwotton


Put your icon inside the element and make it behave as an inline-block so you can change its width and margin.

http://jsfiddle.net/LeBen/B9yjd/

like image 36
LeBen Avatar answered Nov 05 '22 23:11

LeBen


Both, the original code of the Zalando website and the Fiddle by LeBen, are not "ideal" - espacially when it comes to HTML semantics.

Why having empty elements if you only want a background image for an element?

Just add the icon as background-image and set the padding-left for all these elements to the required value.

like image 24
Netsurfer Avatar answered Nov 05 '22 22:11

Netsurfer