代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{margin: 0px; padding: 0px;}
.wrap{height: 400px;width: 100%;border: 1px #ffd83d solid;background-color: snow;display: table;}
.content{vertical-align: middle;display: table-cell;text-align: center;background-color: #d0e9c6;}
</style>
</head>
<body>
<div class="wrap">
<div class="content">
<h1>middle</h1>
</div>
</div>
</body>
</html>
效果图:
有时候需要做出水平和垂直都剧中的效果(类似于登陆框)可采用如下方式:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="app/app13.js"></script>
<style>
*{margin: 0px; padding: 0px;}
.wrap{
width: 80%;
height: 1000px;
margin: 0 auto;
background-color: snow;
}
.content{
width: 550px;
height: 400px;
position: fixed;
left: 50%;
top: 50%;
background-color: #fff;
border-radius: 5px;
border: 1px solid black;
margin-left: -275px;
margin-top: -200px;
}
</style>
</head>
<body>
<div class="wrap">
<div class="content">
<h1>login</h1>
</div>
</div>
</body>
</html>
效果如图:
![](https://i-blog.csdnimg.cn/blog_migrate/9a40317fcfb3d0edc8e40ee72059dff6.png)