把日常開發中反覆用到的片段整理成一份清單,涵蓋文字樣式、相容處理、版面置中與表單美化,遇到時直接抄過去就能用。
::selection{ /* Safari and Opera */
background:#c3effd;
color:#000;
}
::-moz-selection{ /* Firefox */
background:#c3effd;
color:#000;
}
html{ overflow-y:scroll; }
.page-break{ page-break-before:always; }
.page { background-color:blue !important; background-color:red; }
.header{
text-indent:-9999px;
background:url('someimage.jpg') no-repeat;
height: 100px; /*等於圖片高度*/
width:500px;
}
text-indent:-9999px; 的作用是把首行往左推到看不見的地方,同時保留文字以利 SEO 與無障礙閱讀。
#container{
height:auto !important;/*除 IE6 以外的瀏覽器都認 !important*/
min-height:500px;
height:500px;/*值要和 min-height 相同*/
}
a[target="_blank"]:before,
a[target="new"]:before {
margin:0 5px 0 0;
padding:1px;
outline:1px solid #333;
color:#333;
background:#ff9;
font:12px "Zapf Dingbats";
content: "\279C";
}

ol {
font: italic 1em Georgia, Times, serif;
color: #999999;
}
ol p {
font: normal .8em Arial, Helvetica, sans-serif;
color: #000000;
}

p:first-letter{
display:block;
margin:5px 0 0 5px;
float:left;
color:#FF3366;
font-size:3.0em;
font-family:Georgia;
}
.transparent_class {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
line-height:30px;
body{
width:1000px;
margin:0 auto;
}
textarea{ overflow:auto; }
a:active, a:focus{ outline:none; }
幫該元素加上 position:relative;
a[href$='.doc'] {
padding:0 20px 0 0;
background:transparent url(/graphics/icons/doc.gif) no-repeat center right;
}
input[type=submit],label,select,.pointer { cursor:pointer; }
text-transform: capitalize;
font-variant:small-caps;
input[type=text]:focus, input[type=password]:focus{ border:2px solid #000; }
a img{ border:none; }
<form method="post" action="#" > <p><label for="username" >Username</label> <input type="text" id="username" name="username" /> </p> <p><label for="password" >Password</label> <input type="password" id="password" name="pass" /> </p> <p><input type="submit" value="Submit" /></p> </form>
p label{ width:100px; float:left; margin-right:10px; text-align:right; }
label 浮動到左側並固定寬度、文字靠右,輸入框自然排在右邊,就得到一個對齊整齊、又完全語意化的表單。