Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align Text Beside FontAwesome Icon

Hi I'm having trouble trying to align text beside a font awesome icon I've tried a few things but non of them seem to be working what i'm trying to do is make a panel with a button on one side that you can click and it calls the number with the fontawesome icon and text on the other side of the panel (I'm using bootstrap v3.3.2 to build it)

Here an image I've what I'm trying to do enter image description here

and here an image of what it currently looks like enter image description here

<div class="panel panel-default">
  <div class="panel-body">
    <div class="col-lg-8">
      <i class="fa fa-phone fa-2x" style="align: middle;"></i>
      <h3>Call us</h3>
    </div>
    <div class="col-lg-4 text-center">
      <div class="btn-group btn-group-justified" style="align: middle;" role="group" aria-label="...">
        <div class="btn-group" role="group">
          <button type="button" class="btn btn-default" <a href="tel:">Click the button to call us</a>
          </button>
        </div>
      </div>
    </div>
  </div>
</div>
like image 366
reece.78 Avatar asked Feb 18 '15 15:02

reece.78


1 Answers

For posterity, if you are willing to go with CSS flexbox, aligning icons besides text is trivial.

I've kept Bootstrap and its Panel as part of the solution in the spirit of answering the original question.

The key points to note here are:

  • display: flex to make direct children flow in the default direction (row)
  • align-items: center to align along the flex direction (vertical align in this case)
  • flex: 1 to get the middle section to expand as much as possible, pushing the two sides apart

.banner {
  display: flex;
  align-items: center;
}

.banner-start h3 {
  display: inline-block;
}

.banner-start i {
  padding: 0 6px;
}

.banner-middle {
  flex: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="panel panel-default">
  <div class="panel-body">
    <div class="banner">
      <div class="banner-start">
        <i class="fa fa-phone fa-2x"></i>
        <h3>Call us</h3>
      </div>
      <div class="banner-middle">

      </div>
      <div class="banner-end">
        <div class="btn-group" role="group">
          <button type="button" class="btn btn-default"><a href="tel:">Click the button to call us</a>
          </button>
        </div>
      </div>
    </div>
  </div>
</div>
like image 68
Ryan H. Avatar answered Oct 03 '22 15:10

Ryan H.