CSS3 div水平、垂直居中,IE9以上、Firefox、Chrome均正常

时间:2022-06-16 15:02:51
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>水平、垂直居中Div</title>
<meta charset="utf-8" />
<style>
.CenterBox {
position: fixed;
top: 40%;
left: 50%;
background-color: #eee;
border-radius: 15px;
padding: 15px;
width: 350px;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
</style>
</head>
<body>
<div class="CenterBox">
asd
</div>
</body>
</html>