CSS基础学习(二)

11.CSS背景

①设置背景颜色(颜色值通常可以用十六进制(如#000000)或者颜色名称(如red)来表示)

属性:background-color 

例:

body {

background-color:#b0c4de;

}

②背景图像

属性:background-image 

例:

body {

background-image:url('https://static.runoob.com/images/mix/paper.gif');

}

③设置图片平铺

属性:background-repeat

例:

body
{
background-image:url('https://static.runoob.com/images/mix/gradient2.png');
background-repeat:repeat-x;      //只在水平方向平铺
}

body
{
background-image:url('https://static.runoob.com/images/mix/gradient2.png');
background-repeat:repeat-y;      //只在垂直方向平铺
}

body
{
background-image:url('https://static.runoob.com/images/mix/gradient2.png');
background-repeat:no-repeat;      //防止图片平铺
}

④改变图片在背景中的位置

属性:background-position

例:

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

⑤背景图像是否固定

       scroll:背景图片随着页面的滚动而滚动(默认)

       fixed:背景图片不会随着页面的滚动而滚动。

       local:背景图片会随着元素内容的滚动而滚动


例:属性:background-attachment

body {

background-image:url('1.gif');

background-repeat:no-repeat;

background-attachment:fixed;

}

原文地址:https://www.cnblogs.com/zyj3955/p/14698106.html