css简写用法说明

转自:http://my.donews.com/htmlor/2006/10/16/css_shorthand_guide/

font

简写:

font:italic small-caps bold 12px/1.5em arial,verdana;

等效于:

font-style:italic;
font-variant:small-caps;
font-weight:bold;
font-size:12px;
line-height:1.5em;
font-family:arial,verdana;

顺序:font-style | font-variant | font-weight | font-size | line-height | font-family

(注:简写时,font-size和line-height只能通过斜杠/组成一个值,不能分开写。)

background

简写:

background:#fff url(bg.gif) no-repeat fixed left top;

等效于:

background-color:#fff;
background-image:url(bg.gif);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:left top;

顺序:background-color | background-image | background-repeat | background-attachment | background-position

margin & padding

简写:

margin:1px 0 2em -20px;

等效于:

margin-top:1px;
margin-right:0;
margin-bottom:2em;
margin-left:-20px;

顺序:margin-top | margin-right | margin-bottom | margin-left

padding的简写和margin完全一样。

border

简写:

border:1px solid #000;

等效于:

border-width:1px;
border-style:solid;
border-color:#000;

顺序:border-width | border-style | border-color

这三句也是简写,等于是把四边的样式合而为一了。(关于四边的问题,下文有详细说明)

border-top / border-right / border-bottom / border-left

简写:

border-top:1px solid #000;

等效于:

border-top-width:1px;
border-top-style:solid;
border-top-color:#000;

(和border一样)

list-style

简写:

list-style:square outside url(bullet.gif);

等效于:

list-style-type:square;
list-style-position:outside;
list-style-image:url(bullet.gif);

顺序:list-style-type | list-style-position | list-style-image

关于四边

有很多样式都涉及到了四边的问题,这里统一说明。

四边的简写一般如下:

padding:1px 2px 3px 4px;

等效于:

padding-top:1px;
padding-right:2px;
padding-bottom:3px;
padding-left:4px;

顺序:top | right | bottom | left

不论是边框宽度,还是边框颜色、边距等,只要css样式涉及四边,顺序通通都是“上右下左”(顺时针方向)。

如果四边的值省略一个,只写三个:

padding:1px 2px 3px;

则等效于:

padding-top:1px;
padding-right:2px;
padding-bottom:3px;
padding-left:2px;

(省略的“左”值等于“右”)

如果四边的值省略两个:

padding:1px 2px;

则等效于:

padding-top:1px;
padding-right:2px;
padding-bottom:1px;
padding-left:2px;

(省略的“下”值等于“上”)

如果只有一个值:

padding:1px;

则等效于:

padding-top:1px;
padding-right:1px;
padding-bottom:1px;
padding-left:1px;

Tags: css

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

还没有评论。

发表评论

(必填)

(必填)


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.