<!DOCTYPE html>
<html>
<head>
<title>左右垂直居中</title>
<meta charset="utf-8">
<style type="text/css">
/* div{
250px;
height: 250px;
background-color: red;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}*/
div:nth-child(1){
100px;
height: 100px;
background-color: green;
position: absolute;
/*calc css中可以计算的参数calc(计算表达式) 注意:运算符前后必须有空格 否则无效*/
top:calc(50% - 50px);
left: calc(50% - 50px);
}
</style>
</head>
<body>
<!-- <div></div> -->
<div></div>
</body>
</html>