ITeye博客

如何使能DIV垂直和水平居中

lsjlym · 2012-01-26 17:33 · Markdown

<style type="text/css">
.center-middle1 {
position:absolute;
background-color: #e2e2e2;
width: 100%;
height: 300px;
top:50%;
margin-top: -150px; }
.center-middle2 {
position:absolute;
background-color: #e2e2e2;
width: 300px;
height: 200px;
left:50%;
top:50%;
margin-left: -150px;
margin-top: -100px; }

</style>

<style type="text/css"> <!-- .center-middle1 {position:absolute; background-color:#e2e2e2; width:100%; height:300px; top:50%; margin-top:-150px} .center-middle2 {position:absolute; background-color:#e2e2e2; width:300px; height:200px; left:50%; top:50%; margin-left:-150px; margin-top:-100px} --> </style>

用例:

<div class="enter-middle2">
如何使能DIV垂直和水平居中
</div>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。