CSS 的學習终究要靠動手實作與思考,但平時注意收集與整理素材同樣重要,實際開發時往往能事半功倍。以下整理十三組針對按鈕、文字框與表單的樣式,可直接取用再依專案調整。
.buttoncss {
font-family: "tahoma", "新細明體";
font-size: 9pt;
color: #006699;
border: 1px #93bee2 solid;
background: #e8f4ff url(../images/bluebuttonbg.gif);
cursor: pointer;
width: 60px;
height: 22px;
}
.bluebuttoncss {
font-family: "tahoma", "新細明體";
font-size: 9pt;
color: #003366;
border: 1px #93bee2 solid;
background: #fff url(../images/blue_button_bg.gif);
cursor: pointer;
}
.redbuttoncss {
font-family: "tahoma", "新細明體";
font-size: 9pt;
color: #0066cc;
border: 1px #93bee2 solid;
background: #fff url(../images/redbuttonbg.gif);
cursor: pointer;
}
.greenbuttoncss {
font-family: "tahoma", "新細明體";
font-size: 9pt;
color: #0066cc;
border: 1px #93bee2 solid;
background: #fff url(../images/greenbuttonbg.gif);
cursor: pointer;
}
.imagebutton { cursor: pointer; }
body {
font-size: 9pt;
color: #003366;
}
td, th { font-size: 12px; }
舊作中常見的 scrollbar-* 系列屬性(scrollbar-face-color、scrollbar-arrow-color 等)僅 IE 支援,已不建議使用;現在若要自訂捲軸樣式,請改用 ::-webkit-scrollbar 或標準的 scrollbar-color。
select {
font-size: 12px;
color: #003366;
border: 1px solid #b7b7b7;
background-color: #f4f4f4;
}
.editbox {
background: #fff;
border: 1px solid #b7b7b7;
color: #003366;
cursor: text;
font-family: arial, sans-serif;
font-size: 9pt;
height: 18px;
padding: 1px 4px;
}
.multieditbox {
background: #f8f8f8;
border: 1px solid #b7b7b7;
color: #000;
cursor: text;
font-family: arial, sans-serif;
font-size: 9pt;
padding: 4px;
}
.shadow {
position: absolute;
z-index: 1000;
top: 0;
left: 0;
background-color: #ffcc00;
filter: progid:DXImageTransform.Microsoft.dropshadow(
color=#404040, offx=2, offy=2, positive=true);
}
其中的 filter 屬性是 IE 私有寫法,現代瀏覽器請改用 box-shadow: 2px 2px 6px rgba(0,0,0,.4);。
.logintxt {
border: none;
border-bottom: 1px solid #c0c0c0;
background-color: #fff;
font-size: 9pt;
}
.noneinput {
text-align: center;
width: 99%;
height: 99%;
border: none;
background-color: #f6f6f6;
}
早期撰寫表單樣式時,cursor: hand 只有 IE 認得,其他瀏覽器請一律寫 cursor: pointer;另外,<input> 與 <textarea> 的字型不會自動繼承,記得明確指定 font-family,否則在部分環境下會落到系統預設字型。最後別忘了 :focus 狀態——鍵盤使用者需要清楚看到目前游標在哪個欄位,這是無障礙的基本要求:
input:focus, textarea:focus, select:focus {
border-color: #3b7ddd;
outline: 2px solid #3b7ddd;
}