1、為何要縮寫樣式?
對于瀏覽者而言,縮寫可以減少CSS代碼量,進而減少CSS文件體積,有利于訪問者更快的打開網(wǎng)頁;對于開發(fā)者而言,CSS代碼量少,閱讀簡潔明了;對于網(wǎng)站服務(wù)器而言,在相同帶寬下可以承受更多的訪問請求。
2、常用CSS樣式表縮寫語法總結(jié)
● 顏色(color)
16進制的色彩值,如果每兩位的值相同,可以縮寫一半
例如:#000000可以縮寫為#000; #336699可以縮寫為#369;
● 盒尺寸(padding、margin)
順序:從上開始,順時針轉(zhuǎn);margin:上 右 下 左;
上下左右都相等: margin: 5px(上下左右); <==> margin: 5px 5px 5px 5px;
上下相等, 左右相等: margin: 5px(上下) 15px(左右); <==> margin: 5px 15px 5px 15px;
上下不等,左右相等: margin: 5px(上) 10px(左右) 20px(下); <==> margin: 5px 10px 20px 10px
● 邊框(border)
border-width:1px;
border-style:solid;
border-color:#000;
縮寫為 ==> border:1px solid #000;
● 背景(Backgrounds)
background-color: #f00;
background-image: url(background.gif);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 0 0;
縮寫為 ==> background: #f00 url(background.gif) no-repeat fixed 0 0;
你可以省略其中一個或多個屬性值,如果省略,該屬性值將用瀏覽器默認值,默認值為:
color: transparent;
image: none;
repeat: repeat;
attachment: scroll;
position: 0% 0%;
● 字體(fonts)
font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 1em;
line-height: 140%;
font-family: Arial, 宋體;
縮寫為 ==> font: italic small-caps bold 1em/140% Arial, 宋體;
font的縮寫,如果省略family,如這樣子:font: bold 14px/22px; 則在Firefox下是不生效的
完整的寫法是:font: bold 14px/22px arial, 宋體;
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。