垂直水平居中3种方案
1.margin加position
//HTML
<div class="two">
</div>
<div class="one">
</div>
//CSS
.two{
width: 800px;
height: 800px;
background-color: blueviolet;
position: relative;
}
.one{
width: 200px;
height: 200px;
background-color: aquamarine;
position: absolute;
margin:auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
2.transform加position
//HTML
<div class="two">
<div class="one">
</div>
</div>
//CSS
.two{
width: 800px;
height: 800px;
background-color: blueviolet;
position: relative;
}
.one{
width: 200px;
height: 200px;
background-color: aquamarine;
position: absolute;
transform: translate(-50%,-50%);
top: 50%;left: 50%;
}
3. margin加position
//HTML
<div class="two">
<div class="one">
</div>
</div>
//CSS
.two{
width: 800px;
height: 800px;
background-color: blueviolet;
position: relative;
}
.one{
width: 200px;
height: 200px;
background-color: aquamarine;
position: absolute;
top: 50%;left: 50%;
margin-top: -100px;
margin-left: -100px;
}
sass