1、指定容器内垂直居中
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
html,body {
height: 100%;
}
.head{
background-color: #3397DE;
height:15%;
}
.body-content{
position: relative;
background-color: #EBEFF1;
height:75%;
}
.content-middle{
background-color: #2EC35B;
}
.footer{
background-color: #3397DE;
height:10%;
}
/*在body-content指定的范围内垂直居中*/
.absolute-center {
background-color: #807C7C;
width: 50%;
height: 80%;
overflow: auto;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
</style>
</head>
<body>
<div class="head"></div>
<div class="body-content">
<div class="absolute-center"></div>
</div>
<div class="footer"></div>
</body>
</html>
body-content为指定的容器
absolute-center 设置在 body-content中垂直居中。
2、整个页面垂直居中
- .absolute-center {
- margin: auto;
- position: absolute;
- top: 0; left: 0; bottom: 0; right: 0;
- }