Vertical alignment of text and icon in button

前端 未结 3 1515
悲哀的现实
悲哀的现实 2020-12-04 13:59

I\'m having trouble vertically aligning a font-awesome icon with text within a button under the Bootstrap framework. I\'ve tried so many things including setting the line-he

相关标签:
3条回答
  • 2020-12-04 14:34

    Alternativly if your using bootstrap then you can just add align-middle to vertical align the element.

    <button id="whaever" class="btn btn-large btn-primary" style="padding: 20px;" name="Continue" type="submit">Continue
        <i class="icon-ok align-middle" style="font-size:40px;"></i>
    </button>
    
    0 讨论(0)
  • Just wrap the button label in an extra span and add class="align-middle" to both (the icon and the label). This will center your icon with text vertical.

    <button id="edit-listing-form-house_Continue" 
        class="btn btn-large btn-primary"
        style=""
        value=""
        name="Continue"
        type="submit">
    <span class="align-middle">Continue</span>
    <i class="icon-ok align-middle" style="font-size:40px;"></i>
    

    0 讨论(0)
  • 2020-12-04 14:54

    There is one rule that is set by font-awesome.css, which you need to override.

    You should set overrides in your CSS files rather than inline, but essentially, the icon-ok class is being set to vertical-align: baseline; by default and which I've corrected here:

    <button id="whatever" class="btn btn-large btn-primary" name="Continue" type="submit">
        <span>Continue</span>
        <i class="icon-ok" style="font-size:30px; vertical-align: middle;"></i>
    </button>
    

    Example here: http://jsfiddle.net/fPXFY/4/ and the output of which is:

    enter image description here

    I've downsized the font-size of the icon above in this instance to 30px, as it feels too big at 40px for the size of the button, but this is purely a personal viewpoint. You could increase the padding on the button to compensate if required:

    <button id="whaever" class="btn btn-large btn-primary" style="padding: 20px;" name="Continue" type="submit">
        <span>Continue</span>
        <i class="icon-ok" style="font-size:30px; vertical-align: middle;"></i>
    </button>
    

    Producing: http://jsfiddle.net/fPXFY/5/ the output of which is:

    enter image description here

    0 讨论(0)
提交回复
热议问题