<div id="wrapper" style="height:400px;width:400px;">
<div id="example">
Text
</div>
</div>
我正在寻找一种方法让 #example
进入 #wrapper
的中心(左、右、上和下)。
最佳答案
我认为有多种方法可以实现您想要的。一个是:
#wrapper{
display:table-cell;
width:400px;
height:400px;
vertical-align:middle;
border:1px solid red;
}
#example{
width:200px;
margin:auto;
text-align:center;
background:blue;
}
演示:http://jsfiddle.net/SsD4Q/3/
希望对您有所帮助!
关于html - 在父元素中间居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7635139/