我需要跨度使文本在中心對齊。 此前我已經使用line-height來實現此目的,但是在這種情況下,某些項目的文本會更長,並且不再適用。跨度中文本的垂直對齊 - 跨度之外的文本
的jsfiddle:http://jsfiddle.net/4jSdu/
HTML:
<ul>
<li><a><span>Short</span></a>
</li>
<li><a><span>Why Should I Monitor?</span></a>
</li>
</ul>
CSS:
ul {
position: relative;
overflow: hidden;
}
span {
background-color: rgba(216, 25, 11, 0.75);
display: block;
height: 70px;
line-height: 70px;
width: 135px;
color: black;
text-align: center;
/*margin: auto 0;*/
font-weight: bold;
font-size: 15px;
position: absolute;
bottom: 14px;
}
li, a {
width: 135px;
height: 100px;
display: inline-block;
}
編輯:
我想指出,跨度元素具有價值底部:14px的。這個跨度也是動畫效果。當頁面加載跨度有價值底部:-70px(容器已overlfow:隱藏,sö這個跨度是看不到),然後它出現(使用.animate),並下降到14px。所以溶劑應該考慮這一點。
我無法在jsfiddle(http://jsfiddle.net/pr5cL/)中使用此動畫效果,但它適用於本地創建的頁面。
$("ul li:not(.img_active)").mouseenter(function() {
$(this).find("span").css("bottom","-55px");
$(this).find("span").animate({bottom:15},500);
}).mouseleave(function(){
$(this).find("span").animate({bottom:-70},500);
});
這裏是鏈接:http://www.sheerdigitaltest.net/janus/
所以你不知道,如果文本是1或2行,對不對? 是flexbox的一個選項嗎? –
什麼是flexbox? – renathy
這很好,但它確實沒有足夠的瀏覽器支持我的客戶端。 – renathy