我想垂直居中對齊<button>
和<a>
元素。我爲每個CSS內聯塊屬性使用。勉強,我的<a>
鏈接向下移動。HTML/CSS按鈕和一個鏈接垂直對齊
button,
.btn {
display: inline-block;
padding: 0;
margin: 0;
margin-left: 10px;
color: #ffffff;
background-color: #00ade0;
border: 2px solid #fff;
height: 4rem;
width: 4rem;
font-size: 1.5rem;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
line-height: 0;
text-align: center;
text-decoration: none;
}
<button>
1
</button>
<button>
2
</button>
<a href="#" class="btn">
3
</a>
我知道如果我改變行高,它可以解決這個問題,但我不知道爲什麼有line-height:0
,我不能acheive一個想要的東西。
謝謝,這是一個很好的解決方案,似乎工作! :)只是想知道爲什麼高度造成偏移定位問題。 –
這是瀏覽器默認值和'line-height'的組合問題。前者導致您的錨鏈接以不同的默認字體呈現文本,並且「行高」會加劇該問題。通過統一'
謝謝你的回答! :) –