crall

为成为菜鸟而努力···

导航

常用的css缩写

1.字体属性的缩写

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

2.背景属性的缩写

背景的属性如下:

background-color:#f00;

background-image:url(http://blogbeta.blueidea.com/background.gif);

background-repeat:no-repeat;

background-attachment:fixed;

background-position:0 0;

可以缩写为一句:background:#f00 url(http://blogbeta.blueidea.com/background.gif) no-repeat fixed 0 0;
语法是background:color image repeat attachment position;
你可以省略其中一个或多个属性值,如果省略,该属性值将用浏览器默认值,默认值为:

color: transparent

image: none

repeat: repeat

attachment: scroll

position: 0% 0%

3.填充属性的缩写

margin-left:left;

margin-right:right;

margin-top:top;

margin-bottom:bottm;

以上四行代码可缩写为;margin:top right bottom left;(按顺时针排列)这一行代码;

举例:

margin:10px; 等同于margin:10px 10px 10px 10px;

margin:10px 5px;等同于margin:10px 5px 10px 5px;

margin:10px 3px 5px;等同于margin:10px 3px 5px 3px;

同理:内填充padding属性基本一致;

4.边框属性的缩写

边框的属性如下:

border-width:1px;

border-style:solid;

border-color:#000;

可以缩写为一句:border:1px solid #000;

5.列表属性的缩写

取消默认的圆点和序号可以这样写list-style:none;,

list的属性如下:

list-style-type:square;

list-style-position:inside;

list-style-image:url(http://blogbeta.blueidea.com/image.gif);

可以缩写为一句:list-style:square inside url(http://blogbeta.blueidea.com/image.gif);

注:

原文来自:http://home.blueidea.com/space.php?domain=bluetune

根据自己的理解稍作补充说明以便更易理解;

posted on 2011-09-05 15:19  crall  阅读(823)  评论(0编辑  收藏  举报