文章目录
background
属性用于给元素添加背景,可以是背景色,也可以是背景图
background 属性是一个系列属性(综合属性),可以单独设置某个属性也可以综合性的设置;常见的属性有:
background-color
背景颜色background-image
背景图片background-repeat
背景图像是否重复background-position
背景图像位置background-attachment
背景图像附着background-size
背景图片尺寸
background-color
background-color: transparent;
设置元素的背景色;对应的属性值可以是十六进制颜色、rgba、rgb、颜色单词;默认值为 transparent(透明)
background-image
background-image: url(url);
设置元素的背景图片
属性值 | 说明 |
---|---|
none | 无背景图(默认值) |
url | 背景图像的绝对或相对地址 |
如果同时给元素设置背景色和背景图,会优先显示背景图;未被背景图覆盖的区域显示背景色
示例:
div {
width: 500px;
height: 200px;