CSS属性中常见的缩写格式

LMS
1.2K+ 2

CSS的写法中有许多格式可以直接用缩写,掌握这些属性的缩写格式方法在写css的时候会提高不少速度,而且看上去呢还会更显得专业些,嘿嘿。下面列举一二,至于还有没有其他的暂时想不起来了。

1、颜色值的缩写:

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

2、margin与padding的缩写(以margin为例,两者缩写格式一样):

margin:1px = margin:1px 1px 1px 1px;
margin:1px 2px = margin:1px 2px 1px 2px(top bottom,left right对称设置);
margin:1px 2px 3px = margin:1px 2px 3px 2px(第四个默认按第二个);

3、边框属性的缩写:

border-width:1px;
border-style:solid;
border-color:#000;
可以缩写为一句:border:1px solid #000;
语法是border:width style color;

4、背景属性的缩写:

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;
语法是background:color image repeat attachment position;

5、字体属性的缩写:

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两个值

6、列表属性的缩写:

取消默认的圆点和序号可以这样写list-style:none;,
list的属性如下:
list-style-type:square;
list-style-position:inside;
list-style-image:url(image.gif);
可以缩写为一句:list-style:square inside url(image.gif);

THE END

评论 2

发表评论

Submit