[英]align block level element vertically with horizontal width 90%
Ok I can align a content both horizontally and vertically using this好的,我可以使用它水平和垂直对齐内容
<div id="centerId">...content</div>
#contentId {width: 300px; height: 200px; position: absolute; left: 50%; margin-left: -150px; top: 50%; margin-top: -100px; }
Now how to align if I want width to be 90% of the container in which #contentId is.现在,如果我希望宽度为 #contentId 所在容器的 90%,如何对齐。
I usually use two ensted divs as follows...我通常使用两个 ensted div 如下...
<div style="display: block; height: 100%; width: 100%; position:relative; overflow: hidden;margin: 0px auto;">
<div style="position: absolute; top: 40%;left:0px;display: table-cell; vertical-align: middle;text-align:center;">
Content Here...
</div>
</div>
The trick here is the这里的诀窍是
display: table-cell
显示:表格单元格
Give it a try:D试试看:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.