背景
最新更新: 2020-07-23 16:41:26
阅读: 536次
background 简写属性在一个声明中设置所有的背景属性。
语法
background:bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;
可以设置如下属性:
- background-color
- background-position
- background-size
- background-repeat
- background-origin
- background-clip
- background-attachment
- background-image
如果不设置其中的某个值,也不会出问题,比如 background:#ff0000 url('smiley.gif'); 也是允许的。
通常建议使用这个属性,而不是分别使用单个属性,因为这个属性在较老的浏览器中能够得到更好的支持,而且需要键入的字母也更少。
默认值: | not specified |
---|---|
继承性: | no |
版本: | CSS1 + CSS3 |
JavaScript 语法: | object.style.background="white url(paper.gif) repeat-y" |
复合属性的写法
书写格式
background : background-color background-image background-repeat background-attachment background-position;
默认值
background: transparent none repeat scroll 0% 0%;
默认值(中文意思)
background: 透明 / 无背景图片 / 平铺 / 背景图片随文本滚动(不理解的一定要自己动手试一下) / 位于元素左上角
按照以上的方法,将 .sample1 改成 .sample2,可以得到相同的样式。
.sample2 {
background: #CCCCCC url(sample.gif) no-repeat fixed center center;
}