温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何解析CSS缩写六大规则

发布时间:2021-11-18 09:12:26 来源:亿速云 阅读:131 作者:柒染 栏目:web开发

这篇文章将为大家详细讲解有关如何解析CSS缩写六大规则,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

CSS布局有很多值得学习的地方,这里向大家描述一下CSS缩写的规则,使用CSS缩写可以帮助减少你CSS文件的大小,更加容易阅读。

CSS常用缩写语法

使用CSS缩写可以帮助减少你CSS文件的大小,更加容易阅读。CSS缩写的主要规则如下:

颜色

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

#336699可以缩写为#369;

盒尺寸

通常有下面四种书写方法:

property:value1;表示所有边都是一个值value1;
property:value1value2;表示top和bottom的值是value1,right和left的值是value2
property:value1value2value3;表示top的值是value1,right和left的值是value2,bottom的值是value3
property:value1value2value3value4;四个值依次表示top,right,bottom,left
方便的记忆方法是顺时针,上右下左。具体应用在margin和padding的例子如下:

margin:1em02em0.5em;

边框(border)

边框的属性如下:

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

可以缩写为一句:

border:1pxsolid#000;

语法是border:widthstylecolor。

背景(Backgrounds)

背景的属性如下:

background-color:#f00;  background-image:url(background.gif);  background-repeat:no-repeat;  background-attachment:fixed;  background-position:00;

可以缩写为一句:

background:#f00url(background.gif)no-repeatfixed00;

语法是background:colorimagerepeatattachmentposition;

你可以省略其中一个或多个属性值,如果省略,该属性值将用浏览器默认值,默认值为:

color:transparent  image:none  repeat:repeat  attachment:scroll  position:0%0%

字体(fonts)

字体的属性如下:

font-style:italic;  font-variant:small-caps;  font-weight:bold;  font-size:1em;  line-height:140%;  font-family:"LucidaGrande",sans-serif;

可以缩写为一句:

font:italicsmall-capsbold1em/140%"LucidaGrande",sans-serif;

注意,如果你缩写字体定义,至少要定义font-size和font-family两个值。

列表(lists)

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

list的属性如下:

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

可以缩写为一句:

list-style:squareinsideurl(image.gif);

关于如何解析CSS缩写六大规则就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI