<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"content="ie=edge">
<title>div水平垂直居中</title>
<style>
.center {
background-color: #f00;
width: 50%;
height: 50%;
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%)translateY(-50%);
}
</style>
</head>
<body>
<div class="center"></div>
</body>
</html>
第三中方法是比较成熟的不是固定高宽div的垂直居中的方法!但是方法是css3的写法,想兼容IE8的童鞋们,建议用其他方法。