关于CSS的缩写

时间:2014-10-29 来源:极客联盟阅读:2610次类别:网站建设

颜色
16进制的色彩值,如果每两位的值相同,可以缩写一半,例如:#000000可以缩写为#000;#336699可以缩写为#369; #f2f2f2是不可以缩写的

盒模型的边框
border-width:1px; 
border-style:solid; 
border-color:#000; 
可以缩写为一句:
border:1px solid #000; 
语法是border:width style color;

盒模型的边界和填充
margin-top:1px; margin-right:2px; margin-bottom:3px; margin-left:4px;
margin:1px 2px 3px 4px;
注意:这里的顺序是顺时针,分别为:上右下左
margin:1px 2px;
margin:0;
注意:CSS中值为0时可以不带单位,其它时候都必须带单位

背景
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;

字体
font-style:italic; 
font-variant:small-caps; 
font-weight:bold; 
font-size:1em; 
line-height:140%; 
font-family:"Lucida Grande",sans-serif; 
可以缩写为一句:
font:italic small-caps bold 1em/140% "Lucida Grande",sans-serif;
注意,如果你缩写字体定义,至少要定义font-size和font-family两个值。

列表
list-style-type:square; 
list-style-position:inside; 
list-style-image:url(image.gif); 
可以缩写为一句:
list-style:square inside url(image.gif);

0.4802s