Guerrilla Guerrilla - 4 years ago 89
CSS Question

Can't add top margin to icon positioned over button

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?

Answer Source

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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download