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
and here an image of what it currently looks like
<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>
There is a very easy way if your fontawesome has the same font-size than your text (it is usually the good practice), include the tags in the text tags:
Try this :
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 apartTo have complete/independent control on the position of the font-awesome icon, try something like below.
Method 1: Using
absolute positioning
Add
position with
aproperty value
ofrelative
to theh3
style to control overlap.Use
:after
selectorcontent
to insert the iconAdd
position with
aproperty value
ofabsolute
to theh3
:after block of CSS codeAchieve the desired position with left, right, top or bottom property values.
Method 2: Using
float
(Easier).Use
:after
selectorcontent
value to insert the iconAchieve the desired position of the icon by floating the
:before
selector to the right or left.Note: You can adjust the size of the icon with CSS
font-size
property value.Use the .media class.
Sometimes you might need to add position to item. If both elements are on the same column or div and Picture/Icon is larger than something like this should work.