[英]How to horizontally center text without knowing the width of the .div
我正在制作一個展示產品的網格。該網格是由多個div連續組成的,寬度按百分比設置。 是否可以在不更改div設置方式的情況下將文本水平居中?
所有建議都非常歡迎!
的HTML
<div class="container21-b">
<div class="blok21-a">
</a> <a class="text-container-price"> € 29,95 </a>
</div>
</div>
的CSS
.container21-a {
position: relative;
height: 155px;
margin-bottom: 20px;
width: 12.95714%;
float:left;
overflow: hidden;
margin-right: 1.55%;
}
.container21-b {
position: relative;
height: 155px;
margin-bottom: 20px;
width: 12.95714%;
float:left;
overflow: hidden;
}
.blok21-a {
position: relative;
height: 155px;
margin-bottom: 20px;
background-color:#f9f9f9;
}
.blok21-a:hover {
position: relative;
height: 155px;
margin-bottom: 20px;
background-color:#f5f5f5;
}
.text-container-price {
position: absolute;
bottom: 0;
left: 0;
right: 0;
display: inline-block;
font: Verdana;
color: #777;
font-size: 11px;
padding-bottom: 10px;
;
vertical-align: bottom;
}
設置text-align:center;
.blok21-a {
position: relative;
height: 155px;
margin-bottom: 20px;
background-color:#f9f9f9;
text-align:center; /* <------ */
}
這是工作版本: http : //jsfiddle.net/doniyor/PRjU5/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.