父容器 `.out`、子容器 `.in`,需垂直水平居中。
.out { position: relative; width: 300px; height: 300px; background: blue; }
.in { position: absolute; left: 50%; top: 50%;
transform: translate(-50%, -50%);
width: 200px; height: 200px; background: red; }
.out { display: flex; justify-content: center; align-items: center;
width: 300px; height: 300px; background: blue; }
.in { width: 200px; height: 200px; background: red; }
.out { display: grid; place-items: center; }
.in { position: absolute; left: 50%; top: 50%;
margin-left: -100px; margin-top: -100px; } /* 寬高一半 */
總結:**Flexbox (`align-items:center`) 為現代首選**,Absolute+Transform 兼容舊瀏覽器/特殊場景,Grid 極簡但兼容性稍弱。