center with "transform"
重點
.centered-element {
margin: 0;
/* ⭐️ child 跟隨 parent 的坐標系 */
position: absolute;
/* ⭐️ 垂直水平置中 */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
程式碼
Last updated
Was this helpful?
.centered-element {
margin: 0;
/* ⭐️ child 跟隨 parent 的坐標系 */
position: absolute;
/* ⭐️ 垂直水平置中 */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Last updated
Was this helpful?