<html>
<head><title>postion方式的居中</title>
<style>
div{
width: 200px ;
height: 200px ;
background: red ;
position: absolute ;
left: 50% ;
top: 50% ;
margin-top: -100px ;
margin-left: -100px ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
以上是使用postion的方式来使得DIV上下左右一直在中间,DIV的大小不会变。
<html>
<head><title>margin方式的居中</title>
<style>
body{
margin: 0px;
padding: 200px;
}
div{
width: 100% ;
height: 100% ;
background: red ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
以上是使用margin的方式是的DIV居中,他的形状取决于什么,希望大家自己仔细看看。