<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; }
.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>
如何使能DIV垂直和水平居中
</div>
本文详细介绍了如何使用CSS将DIV元素垂直和水平居中,包括使用百分比定位、Flex布局和Grid布局的方法。

被折叠的 条评论
为什么被折叠?



