這個做法的核心是一個漂亮的對消:用超大的 padding-bottom 把區塊撐長,再用等量的負 margin-bottom 把它「按回去」。視覺上區塊變高了,實際佔用的版面高度卻沒變。
#sideleft, #sideright {
padding-bottom: 32767px !important;
margin-bottom: -32767px !important;
}
32767px 是刻意選的極大值,確保任何真實內容都不會撐破它。兩者數值相同、方向相反而互相抵銷,於是欄位背景延伸到容器底部,而後續元素仍緊接在正確位置。
純粹的 padding/margin 對消在部分舊版 Opera 上會出問題,因此原方案額外補了一段分流:
@media all and (min-width: 0px) {
#sideleft, #sideright {
padding-bottom: 0 !important;
margin-bottom: 0 !important;
}
#sideleft:before, #sideright:before {
content: '[DONOTLEAVEITISNOTREAL]';
display: block;
background: inherit;
padding-top: 32767px !important;
margin-bottom: -32767px !important;
height: 0;
}
}
支援條件的瀏覽器會把對消動作移到 :before 擬元素上,避開原版的相容問題;不支援的則走前面的規則。那段看起來像亂碼的 content 文字是刻意的哨兵值,用來避免某些引擎對空內容做最佳化而讓擬元素消失。
欄位都浮動了,容器就會塌陷,所以還需要一段 clearfix:
#wrap:after {
content: '';
display: block;
height: 0;
clear: both;
visibility: hidden;
}
優點是不需要事先知道哪一欄最高,也不需要背景圖,容易套用。缺點是 hack 數量偏多(主要是為了解決舊 Opera),程式碼對後人不太友善。
以今天的標準看,這類技巧已被 CSS Grid 與 Flexbox 徹底取代——align-items: stretch 一行就能做到等高。理解它的價值在於看懂老專案,以及體會「用對消換取視覺效果」這種思路。