BLOG
Enjoy when you can, and endure when you must.
OCT 30, 2012/CSS
常见的CSS简写规则

CSS简写也是代码优化中的一个重要的环节,这样有利于缩减CSS文件的大小,增加效率。

这里整理了一些常见的简写规则。

一、外边距(margin):

margin-top、margin-right、margin-bottom、margin-left

简写顺序为顺时针方向(上、右、下、左),如:margin: 1px 2px 3px 4px;

其中四边都相等时可简写为一个,如:margin: 1px;

当上下、左右分别相等时,也可简写,如:margin: 1px 2px; 代表上下1px,左右2px

只有左右相等时,可简写为:margin: 1px 2px 3px;

但只有上下相等时不可简写。

内边距(padding)与此规则相同。

二、边框(border):

border:2px solid #cdcdcd;

分别为border-width、border-style、border-color

除border-style必须提供之外,其它都可省略而使用默认参数,其中border-width默认为3px,border-color默认为黑色。

三、字体(font):

这是在网上搜集的一张图,归纳的不错:

四、背景(background):

 

background:#fff url(...) repeat fixed 0 0;

分别为background-color、background-image、background-repeat、background-attachment、background-position

 

五、列表(list-style):

list-style:disc outside url(list.png)

分别为list-style-type、list-style-position、list-style-image

 

六、颜色(color):

这个很直观,就是像:#xxyyzz即可简写为#xyz

COMMENTS
LEAVE COMMNT