实现效果:
不管窗口尺寸大小,都可以实现水平和垂直居中
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>居中效果</title>
<link href="style.css" rel="stylesheet" />
<style type="text/css">
.panel{
width: 0;
height: 0;
position: fixed;
left: 50%;
right: 50%;
top: 50%;
bottom: 50%;
}
.image{
width: 500px;
height: 500px;
margin-left: -250px;
margin-top: -250px;
background-color: red;
}
</style>
</head>
<body>
<div class="panel">
<div class="image">
</div>
</div>
</body>
</html>