(1)背景颜色(background-color)
background-color属性设置一个元素的背景颜色。元素的背景是元素的总大小,包括填充和边界(但不包括边距)。
指定背景颜色透明时可使用transparent作为属性值。
语法格式:
<style>
div {
background-color: red;
background-color: transparent; /* 透明 */
}
</style>
(2)背景图片(background-image)
background-image属性设置一个元素的背景图像。元素的背景是元素的总大小,包括填充和边界(但不包括边距)。默认情况下,background-image放置在元素的左上角,并重复垂直和水平方向。
提示:请设置一种可用的背景颜色,这样的话,假如背景图像不可用,可以使用背景色带代替。
语法格式:
<style>
div {
background-image: url('图片路径'); /*设置图片显示*/
}
</style>
(3)背景平铺(background-repeat)
设置如何平铺对象的 background-image 属性。默认情况下,重复background-image的垂直和水平方向。
语法格式:
<style>
div {
background-repeat: repeat-y;
}
</style>
属性值:
值 | 说明 |
---|---|
repeat | 背景图像将向垂直和水平方向重复 | 默认值 |
repeat-x | 只有在水平方向会重复背景图像 |
repeat-y | 只有在垂直方向会重复背景图像 |
no-repeat | 不会重复 |
(4)背景位置(background-position)
background-position属性设置背景图像的起始位置
第一个值表示水平方向,值增大时,意味着背景图片向右移动。
第二个值垂直方向,值增大时