首页 > 代码库 > css3固定居中

css3固定居中

<!DOCTYPE html>
<html>
<head>
<title>左右垂直居中</title>
<meta charset="utf-8">
<style type="text/css">
/* div{
width: 250px;
height: 250px;
background-color: red;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}*/
div:nth-child(1){
width: 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>

css3固定居中