-1

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>
j08691
  • 204,283
  • 31
  • 260
  • 272
Atma
  • 29,141
  • 56
  • 198
  • 299

2 Answers2

3

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>
j08691
  • 204,283
  • 31
  • 260
  • 272
1

Just add line-height: 55px; to the link.

.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>
paolobasso
  • 2,008
  • 12
  • 25