置中(CSS)
code:css
.parent {
display: flex;
justify-content: center;
align-items: center;
}
2. position: absolute + margin: auto
3. flexbox
code:css
.parent {
display: flex;
justify-content: center;
align-items: center;
}
4. display: table-cell
code:css
.parent {
display: grid;
place-items: center;
}
code:css
.parent {
contain: content;
}
.child {
position: absolute;
inset: 0;
margin: auto;
}
code:css
th {
text-align-last: justify;
}
top: 50%; left: 50%;
元素以左上角為錨點
移動母元素一半的長寬=母元素的中心處
transform: translate(-50%, -50%)
往回移動元素自身一半的長寬
補回因為基準點在左上而需要的距離差