使用CSS缩写

CSS缩写
零、background缩写
1、background属性的值的书写顺序官方没有强制标准。
2、为了可读性,一下顺序是符合CSS书写规范的

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

#content {
	background: #EDEDED url(img/bg.gif) no-repeat 30% 20px;
}

一、font字体缩写

font:font-style | font-variant | font-weight | font-size | line-height | font-famliy
//只要使用font作为属性名称,后接各个属性的值即可,各个属性值之间使用空格分开,不需要的参数可以之间去掉
例如:
p{ font: italic normal bold 12px/18px 宋体}

此代码将使p对象字体成为:斜体 大小写默认、加粗、12px大小、18px行高、宋体。
因为CSS各个属性的值写法并不相同,因此直接去掉某个参数不会影响顺序;与值得关系。
但是也有意外,比如比例中的12px/18px指的是font-size和line-height。用反斜线分隔,因为
font-size与line-height的值使用的是同一套数值。

font的简写注意事项

  1. 简写时,font-size和line-height只能通过斜杠/组成一个值,不能分开写。
  2. 顺序不能改变.这种简写方法只有在同时指定font-size和font-family属性时才起作用。而且,如果你没有设定font-weight, font-style, 以及 font-varient ,他们会使用缺省值
    总结:也就是说当使用font简写时,font-size和font-family是必填项,且顺序不能改变

二、margin与padding边距缩写
仅以margin为例,padding与margin缩写相同
四个参数是
margin:margin-top | margin-right | margin-bottom | margin-left
一个参数和两个参数的好理解
margin: 20px;(上、下、左、右各20px。)
margin: 20px 40px;(上、下20px;左、右40px。)
p{margin: 20px 10px 100px;}
三个参数则表示margin-top = 20px, margin-left = margin-right = 10px, margin-bottom = 100px

三、border缩写
border对象是个非常复杂的对象,它包含四条边的不同宽度、颜色,yiji以及不同样式。我们对border
的缩写有三种

1.对整个对象进行border缩写
p{border:1px solid blue;}
p对象将被设置4个边均为1px宽度、实线、蓝色边框的样式。

2.对border的4个边应用单独的样式,
border-top:border-width | border-style | border-color
right bottom left都一样 例如:

p{
	border-top:1px solid blue;
	border-right:1px dashed red;
}

上边框我们设置为1px蓝色实线,右边框则是1px红色虚线。

3.对border-style,border-width以及border-color。

border-width:top | right | bottom | left
border-style:top | right | bottom | left
border-color:top | right | bottom | left

同margin和padding缩写一样,并且支持1~4个参数不同的缩写方式。

四、list列表缩写
list缩写是针对list-style-type,list-style-position等用与ul的list属性,语法如下:

list-style:list-style-type | list-style-position | list-style-image
代码示例

ul{list-style:disc outside none}

ul 对象将被设置为圆点、出现在对象外、不带图像的list-style样式。

五、颜色缩写
相同的两个16进制数可以缩写 比如:
#FFFFFF缩写为#FFF #2255BB缩写为#25B

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值