今天,我在使用border-radius
創建的圓圈元素內垂直居中放置一些小文本時遇到了很多麻煩。在邊界半徑創建的圓圈內垂直居中文本
一些元素看起來不錯,但其中一個(小寫字母和太接近底部);我有的padding
它看起來很好;然而,一旦在移動設備上觀看,它稍微低一點。
下面是一些代碼,儘可能接近副本,因爲我可以想出問題;您會注意到此文本與小寫字母和太接近底部有類似的問題。
HTML:
<div class="option">
<span class="icon">t</span>
<span class="text">123456789</span>
</div>
<div class="option">
<span class="icon">f</span>
<span class="text">123456789</span>
</div>
<div class="option">
<span class="icon">e</span>
<span class="text"><a href="mailto:[email protected]">[email protected]</a></span>
</div>
CSS:
.option {
margin-bottom: 10px;
font-family: 'Source Sans Pro', sans-serif;
font-size: 14px;
}
.option .icon {
display: inline-block;
text-align: center;
width: 24px;
height: 24px;
line-height: 24px;
color: #fff;
border-radius: 50%;
background-color: blue;
}
.option .text {
padding-left: 10px;
}
的jsfiddle:http://jsfiddle.net/7bygsgn1/7/
雖然我還沒有上的jsfiddle特定代碼嘗試過的時候,我遇到了這個問題一天我嘗試的整個範圍的中心的技術,包括:
- 使用
line-height
- 使用
absolute
定位 - 結合使用
vertical-align: middle;
與display: table-cell;
- 緣陰性
- 使用方法說明here。
要麼它沒有影響對中或導致圓的形狀改變。
有沒有什麼辦法可以在這種情況下可靠地垂直居中?
我跑了你的第一個建議片段,它看起來不錯,但是當我將它添加到我的小提琴的叉子時,* e *仍然太低 - 我錯過了什麼? http://jsfiddle.net/mn77cz9r/1/ - 至於flex,我需要支持IE9 - 有沒有優雅的後備? – Brett
@Brett,你忘了刪除行高的屬性,這是不再需要和周圍的東西:) http://jsfiddle.net/7bygsgn1/11/ –
啊,謝謝! :)我可以問問這是如何工作的嗎?如何在圖標元素修復對齊之前添加空元素? – Brett