设置背景颜色:值可以直接写英文字母,也可以写十六进制,也可以写rgb
background-image: url(‘img/timg2.jpg‘); 引入背景图片
background-repeat: no-repeat; 背景图片平铺,默认为平铺。no-repeat:不平铺;repeat-x:水平方向平铺;repeat-y:垂直方向平铺
background-position: right bottom; 背景图片位置:第一个值:水平方向位置,可以直接写具体的值,也left/center/right;第二个值:垂直方向位置,可以直接写具体的值,也top/center/bottom
background-size: 50% 50%; 背景大小,参照物为元素本身。第一个值:水平方向大小;第二个值:垂直方向大小。也可以写cover。
background: url(‘img/timg2.jpg‘) no-repeat 100px center tomato;
注意:backgroun-size不能和别的属性一起写
第一个值:图片路径
第二个值:平铺方式
第三个值:水平方向位置
第四个值:垂直方向位置
第五个值:背景颜色
案例:
(1)html
<div></div>
<p></p>
(2)css
div{
width: 100px;
height: 100px;
background: rgb(174,65,65);
}
p{
height: 500px;
border: 1px solid #000;
background: url(‘img/timg2.jpg‘) no-repeat 100px center tomato;
}
原文:https://www.cnblogs.com/msw0803/p/11525892.html