[英]make the element in the div align vertically middle
這是實例:
div #con是搜索結果面板,我希望以列表方式顯示搜索項目,帶有圖標和文本。
現在我不能使圖標垂直對齊,使文本在圖像的中心位於“1”“2”。
有什么建議嗎?
我用了 :
div.item div.img {
float: left;
width: 22px;
height: 25px;
background-image: url('http://i.stack.imgur.com/NpSHB.gif');
background-repeat: no-repeat;
background-position: center left;
text-align: center;
vertical-align: middle;
}
我已經更新了小提琴 。 那是你需要的嗎?
使用行高 - 垂直對齊:塊級元素,如div對垂直對齊沒有任何影響。 您需要使用行高或使用div作為相對的絕對定位。
你需要修改CSS
div.item div.img{ text-align:center;
margin-top:2px; /*can change this according to your need */
}
添加這兩個屬性。 垂直對齊不起作用。 小提琴http://jsfiddle.net/NjnAF/2/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.