子元素在父元素里面水平居中的方法:
第一个用绝对定位和转换
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.box{
width: 300px;
height: 300px;
background-color: red;
position: relative;
}
.box1{
width: 100px;
height: 100px;
background-color: #35B1FF;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div class="box">
<div class="box1">
</div></div>
</body>
</html>
第二种:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.box{
width: 300px;
height: 300px;
background-color: red;
}
.box1{
width: 100px;
height: 100px;
background-color: #35B1FF;
transform: translate(100px,100px);
}
</style>
</head>
<body>
<div class="box">
<div class="box1">
</div>
</div>
</body>
</html>