未知宽高元素居中
有两种方法
使用flex
父元素:
1
2
3
4
5
6
7
8width: 100vw;
height: 500px;
background: skyblue;
/* position: relative; */
display: flex;
/* align-content: center; */
justify-content: center;
align-items: center;子元素不用设置
使用transform
父元素:
1
2
3
4width: 100vw;
height: 500px;
background: skyblue;
position: relative;子元素:
1
2
3
4
5
6
7position: absolute;
top: 50%;
left: 50%;
width: 200px;
transform: translate(-50%, -50%);
word-break: break-all;
background-color: deepskyblue;