水平垂直居中

 

 

 

<!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>垂直居中</title>
<style>

*{
margin: 0;
padding: 0;
}


html,body{
height:100%;
}
 
#bg{
height:100%;
background: powderblue;
width: 100%;
}

#inner{
background: blueviolet;
height:240px;
width:240px;
position: absolute;
top:50%;
left:50%;
transform: translate(-120px,-50%);
}
 
 
</style>
</head>
<body>
 
<div id="bg">

<div id="inner"></div>
 
</div>
</body>
</html>
 
 
CSS权值:
 
事件冒泡与事件捕获:

 


 

 

posted @ 2018-03-29 11:05  hh9515  阅读(103)  评论(0编辑  收藏  举报