现在搜索链接卡在div的顶部。如何使此链接在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>
答案 0 :(得分:3)
最简单的方法是在链接上设置行高以匹配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;
}
&#13;
<div class="advanced-button">
<a href="#">Search Now<i class="fa fa-search"></i></a>
</div>
&#13;
答案 1 :(得分:1)
只需在链接中添加line-height: 55px;
即可。
.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>