下拉選單 select 的樣式向來是跨瀏覽器的一大痛點,不同瀏覽器對它的解讀差異極大。本文示範如何設定樣式,讓它在 IE6/IE7/IE8 與 Firefox 上都有一致的外觀。
.select_border{
width:59px;
height:29px;
*background:#fff;
background:#fff;
*border:1px solid #09f;
*padding:4px;
*height:20px;
}
.container{
*border:0;
*position:relative;
*height:18px;
*overflow:hidden;
}
.select{
border:1px solid #09f;
padding:4px 3px;
font-size:12px;
height:30px;
width:60px;
*width:52px;
margin:-1px;
}
.select_border,.container { *width:50px; }
把 select 包進 .container,再包進 .select_border。帶星號 * 的屬性只對 IE 生效,藉此微調各版本 IE 的寬高與邊框,讓最終外觀在各大瀏覽器間保持一致。