![](/img/trans.png)
[英]Align image and text inside <div> horizontally and vertically
[英]Horizontally align text inside a DIV container
我有一個像這樣的結構:
<div class="content-wrapper">
<div class="left-wrapper">
Lorem Ipsum... <!-- This is what I want horizontally aligned -->
</div>
</div>
我的CSS文件就像:
.content-wrapper {
min-height: 200px;
width: 100%;
}
.content-wrapper left-wrapper {
min-height: inherit;
width: 50%;
float: left;
}
我想做的是:不管left-wrapper
內的文本有多大,例如,我都希望padding-top
和padding-bottom
等於30px
,並且我的文本水平完美對齊。
提前致謝!
CSS:
.content-wrapper .left-wrapper {
min-height: inherit;
width: 50%;
float: left;
text-align:center;
padding:30px 0;
}
這是一個JSBIN。
.content-wrapper .left-wrapper {
min-height: inherit;
width: 50%;
float: left;
text-align: center;
}
您可以在這里檢查: http : //jsfiddle.net/0dfxv8tw/
在您的代碼中替換
.content-wrapper left-wrapper {
與
.content-wrapper .left-wrapper {
並提供
text-align: center;
<div class="div01">
<div class="div02">
<div class="div03">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</div>
</div>
*{margin:0; padding:0; font-size:12px; color:#333; font-family:Arial;}
.div01 {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
.div02{
height:100%;
width:100%;
display:table;
}
.div03 {
vertical-align:middle;
height:100%;
display:table-cell;
border:1px solid #000;
line-height:22px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.