Reputation: 14906
I am adding a fontawesome icon to a button like so:
#wrapper{
text-align: center;
}
#wrapper:after{
content: "\f0a9";
font-family: 'FontAwesome';
color: #000;
font-size: 16px;
margin-left: -30px;
}
#button{
padding-right: 30px;
height: 40px;
}
<div id="wrapper">
<input id="button" type="submit" value="Download Now"/>
</div>
The problem is the icon doesn't look quite right. It's a few pixels too high but I can't figure out how to adjust it. Margin and padding move the button as well so it doesn't change anything. Playing with vertical-align changes it but its still a few pixels out and I want a pixel perfect placement.
How do I lower/higher the icon?
Upvotes: 1
Views: 1402
Reputation: 190
If you put your wrapper next to the input
and change it to position: absolute
with the height
matching the input's line-height it should do the trick:
#wrapper{
text-align: center;
}
#wrapper:after{
content: "\f0a9";
font-family: 'FontAwesome';
color: #000;
font-size: 16px;
margin-left: -30px;
position: absolute;
line-height: 40px;
}
#button{
padding-right: 30px;
height: 40px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<input id="button" type="submit" value="Download Now" /><span id="wrapper"></span>
It also has the added advantage of matching the height of the input, so you don't have to use trial and error to guess the top margin.
Upvotes: 0
Reputation: 53709
Adding position: relative;
and top: 3px;
will move it down a few pixels.
#wrapper{
text-align: center;
}
#wrapper:after{
content: "\f0a9";
font-family: 'FontAwesome';
color: #000;
font-size: 16px;
margin-left: -30px;
position: relative;
top: 3px;
}
#button{
padding-right: 30px;
height: 40px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="wrapper">
<input id="button" type="submit" value="Download Now"/>
</div>
Upvotes: 4