回顾flex布局
參看 https://www.cnblogs.com/hellocd/p/10443237.html
<div style="border: 1px red solid;display: flex;justify-content: space-around;">
<div style="background: red;width: 200px;height: 200px;">
<div style="background: blueviolet;width: 100px;height: 100px;"></div>
</div>
**回顾相对定位和绝对定位 相对定位和绝对定位**
<div style="background: red;width: 200px;height: 200px; position: absolute;">
<div style="background: blueviolet;width: 100px;height: 100px; position: relative;
top: 50px;left: 50px;"></div>
</div>
<div style="background: red;width: 200px;height: 200px;">
<div style="background: blueviolet;width: 100px;height: 100px;"></div>
</div>
<div style="background: red;width: 200px;height: 200px;">
<div style="background: blueviolet;width: 100px;height: 100px;"></div>
</div>
</div>
技巧一:盒子始终属于上下左右居中位置
如上图所示 我们想要一个盒子上下左右居中在屏幕中间,并且盒子高度和宽度是不固定的,我们可以这么做
<body class="parent">
<form class="child">
4444444444444444444444444444444444444444444
444444444444444444444444444444444444444444444444444444
444444444444444444444444444444444444444444444444444444
</form>
</body>
<style>
.parent{
background: gainsboro;
}
.child{
border: 1px red solid ;
width: 500px;
position: absolute;
word-wrap: break-word; //超出宽度自动换行
top: 50%;
left: 50%;
//向X轴平移,填正数往右平移,填负数,往左平移
transform: translate(-50%, -50%);
}
</style>