screen 媒體類型常被忽視?@media 規則能針對不同輸出裝置套用樣式。print 媒體廣為人知(列印樣式),但 screen 常被視為「預設呈現」而未被充分利用。實際上,在絕對定位佈局中,screen 媒體類型具有關鍵意義。
開發 Ajax Web 應用時,需在螢幕固定位置建立介面元件(如橫跨底部的工具列)。常見做法:
<iframe> 或 <div> 配合 position: fixed。<div> 可視性的能力。最佳方案:純 CSS 實現固定定位佈局。
目標:建立類似圖 1 的介面——頂部內容區可捲動,底部工具列固定。

<html>
<head><title>Using CSS media types</title> @CSS </head>
<body>
<div class="top"> @ITEMS </div>
<div class="bottom"> @SUMMARY </div>
</body>
</html>
div.bottom {
background-color: lightblue;
position: absolute;
bottom: 0; left: 0; right: 0;
height: 20px;
}
div.top { background-color: white; }
li.odd { background-color: #EAEAFF; }
li.even { background-color: #FCFCFC; }
此時向下捲動 .top 區塊時,工具列會被內容遮蓋(見圖 2)。

@media screen 修正固定定位關鍵在於針對螢幕媒體套用 position: fixed,而列印媒體保持預設流式佈局:
@media screen {
div.bottom {
position: fixed;
bottom: 0; left: 0; right: 0;
}
div.top {
margin-bottom: 20px; /* 為固定底部預留空間 */
}
}
@media print {
div.bottom { position: static; }
div.top { margin-bottom: 0; }
}
此做法確保:
screen 媒體類型非單純「預設」,而是「互動式視覺裝置」的精準標識。@media screen 與 position: fixed,可在不使用框架、不依賴 JS 的情況下實現穩固的固定定位 UI。