WD1X.COM - 问答一下,轻松解决,电脑应用解决专家
主板显卡CPU内存显示器
硬盘维修显卡维修显示器维修
注册表系统命令DOS命令Win8
存储光存储鼠标键盘
内存维修打印机维修
WinXPWin7Win11Linux
硬件综合机箱电源散热器手机数码
主板维修CPU维修键盘鼠标维修
Word教程Excel教程PowerPointWPS
网络工具系统工具图像工具
数据库javascript服务器
PHP教程CSS教程XML教程

CSS教程:汇总CSS属性的缩写(2)

更新时间:2011-03-19 15:24 作者:佚名点击:

background的简写可以大大的提高css的效率:

1
background:#fff url(img.png) no-repeat 0 0;

background的简写也有些默认值:

1
background:transparent none repeat scroll top left ;

background属性的值不会继承,你可以只声明其中的一个,其它的值会被应用默认的。

font

font简写也是使用最多的一个,它也是书写高效的CSS的方法之一。

font包含以下属性:

1
2
3
4
5
6
font-style: normal    italic    oblique;
font-variant:normal    small-caps;
font-weight: normal    bold    bolder       lighter    (100-900);
font-size: (number+unit)    (xx-small - xx-large);
line-height: normal    (number+unit);
font-family:name,"more names";

font的各个属性也都有默认值,记住这些默认值相对来说比较重要

1
2
3
4
5
6
font-style: normal;
font-variant:normal;
font-weight: normal;
font-size: inherit;
line-height: normal;
font-family:inherit;

事实上,font的简写是这些简写中最需要小心的一个,稍有疏忽就会造成一些意想不到的后果,所以,很多人并不赞成使用font缩写

不过这里正好有个小手册,相信会让你更好的理解font的简写:


CSS

列表样式

可能大家用的最多的一条关于列表的属性就是:

1
list-style:none

它会清除所有默认的列表样式,比如数字或者圆点。

list-style也有三个属性:

1
2
3
list-style-type:none    disc    circle    square    decimal    lower-alpha    upper-alpha    lower-roman    upper-roman
list-style-position:  inside    outside    inherit
list-style-image:  (url)    none    inherit

list-style的默认属性如下:

1
list-style:disc outside none

需要注意的是,如果list-tyle中定义了图片,那么图片的优先级要比list-style-type高,比如:

list-style:circle inside url(../img.gif)

这个例子中,如果img.gif存在,则不会显示前面设置的circle符号。

PS:其实list-style-type有很多种很有用的样式,感兴趣的同学可以参考一下:https://developer.mozilla.org/en/CSS/list-style-type

border-radius(圆角半径)

border-radius是css3中新加入的属性,用来实现圆角边框。这个属性目前不好的一点儿是,各个浏览器对它的支持不同,IE尚不支持,Gecko(firefox)和webkit(safari/chrome)等需分别使用私有前缀-moz-和-webkit-。更让人纠结的是,如果单个角的border-radius属性的写法在这两个浏览器的差异更大,你要书写大量的私有属性:

1
2
3
4
5
6
7
8
9
-moz-border-radius-bottomleft:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
-webkit-border-bottom-left-radius:6px;
-webkit-border-top-left-radius:6px;
-webkit-border-top-right-radius:6px;
border-bottom-left-radius:6px;
border-top-left-radius:6px;
border-top-right-radius:6px;

呃,是不是你已经看的眼花了?这只是要实现左上角不是圆角,其它三个角都是圆角的情况。所以对于border-radius,神飞强烈建议使用缩写:

1
2
3
-moz-border-radius:0 6px 6px;
-webkit-border-radius:0 6px 6px;
border-radius:0 6px 6px;

这样就简单了很多。PS:不幸的是,最新的Safari(4.0.5)还不支持这种缩写… (thanks @fireyy)

就总结这么多,还有其它的可以缩写的属性吗?欢迎大家提出一起讨论。

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
你可能感兴趣的内容