Atma Atma - 1 month ago 6
CSS Question

how vertically center link in div

The search now link is stuck aligned to the top of the div. How do I make this link centered vertically in the div?



.advanced-button {
width: 200px;
height: 55px;
background-color: #f4c23d;
line-height: 40px;
}
.advanced-button a {
margin-left: 15px;
font-size: 16px;
font-family: 'Montserrat', sans-serif;
color: #222222;
font-weight: 700;
text-transform: uppercase;
vertical-align: middle;
}
.advanced-button i {
float: right;
width: 40px;
height: 55px;
line-height: 40px;
text-align: center;
background-color: #f0b20e;
}

<div class="advanced-button">
<a href="#">Search Now<i class="fa fa-search"></i></a>
</div>




Answer

The easiest way would be to set the line height on the link to match the height of the div:

.advanced-button {
  width: 200px;
  height: 55px;
  background-color: #f4c23d;
  line-height: 40px;
}
.advanced-button a {
  margin-left: 15px;
  font-size: 16px;
  font-family: 'Montserrat', sans-serif;
  color: #222222;
  font-weight: 700;
  text-transform: uppercase;
  vertical-align: middle;
  line-height:55px;
}
.advanced-button i {
  float: right;
  width: 40px;
  height: 55px;
  line-height: 40px;
  text-align: center;
  background-color: #f0b20e;
}
<div class="advanced-button">
  <a href="#">Search Now<i class="fa fa-search"></i></a>
</div>