1. 程式人生 > >盒子水平垂直居中之 flex

盒子水平垂直居中之 flex

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>標題</title>
<style type="text/css">
*{
margin: 0;
padding-top:0;
}
.box1{
  width:400px;
  height:400px;
  background-color: pink;
}
.box2{
background-color: red;
width: 200px;
background-color: red;
}
.father{
 display: flex;
 justify-content: center;
 align-items: center;
}
.son{


}





</style>
</head>
<body>
  <div class="box1 father">
    <div class="box2 son">I'am son,want in distance of center</div>
  </div>

</body>
</html>