固定寬高的元素要絕對置中,可用 top: 50%、left: 50%,再用負 margin 拉回一半寬高。
.content {
width: 400px;
height: 300px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -200px;
margin-top: -150px;
}若有 border,需將 border 寬度納入 margin 計算。父層若需作為定位參考,也要設定 position: relative。