CSS基础(2)

3.css背景

 css背景属性用于定义元素的背景效果。

背景属性包括:

(1)background-color

(2)background-image

(3)background-repeat

(4)background-attachment

(5)background-position

 

 

(1)background-color:指定义元素的背景颜色

例:

body{

     background-color:red;

}

(2)background-image:指定义元素的背景图片

例:

body{

        background-image:url("tupian.jpg")

}

 

(3)background-repeat:背景重复

  background-repeat:no-repeat;属性还可指定只显示一次背景图像:

例:

body {
  background-image: url("tree.png");
  background-repeat: no-repeat;
}

 

 

 

(4)background-attachment:背景图片是滚动还是附着

  例:固定

 

body {
  background-image: url("tree.png");
  background-repeat: no-repeat;
  background-position: right top;
  background-attachment: fixed;
}

 


 

 

(5)background-position:背景图像的定位

 

 例:

body {
  background-image: url("tree.png");
  background-repeat: no-repeat;
  background-position: right top;
}

 

posted @ 2021-11-13 11:18  Purgatory  阅读(70)  评论(0)    收藏  举报