背景颜色_background-color
/* 默认背景色是透明;背景色在背景图之下*/
background-color: transparent;
背景图片_background-image
<style>
.box {
width: 100%;
/* 元素必须给一个尺寸才能显示背景图 */
height: 500px;
background-image: url(https://cn.bing.com/th?id=OHR.FanjingStairs_ZH-CN0360402048_UHD.jpg&rf=LaDigue_UHD.jpg&w=300&h=300&c=8&rs=1&o=3&r=0);
}
</style>
<div class="box"></div>
背景重复_background-repeat
<style>
.box {
width: 100%;
/* 元素必须给一个尺寸才能显示背景图 */
height: 500px;
background-image: url(https://cn.bing.com/th?id=OHR.FanjingStairs_ZH-CN0360402048_UHD.jpg&rf=LaDigue_UHD.jpg&w=300&h=300&c=8&rs=1&o=3&r=0);
background-repeat: no-repeat;
}
</style>
<div class="box"></div>
背景位置_background-position
<style>
.box {
width: 100%;
/* 元素必须给一个尺寸才能显示背景图 */
height: 500px;
background-image: url(https://cn.bing.com/th?id=OHR.FanjingStairs_ZH-CN0360402048_UHD.jpg&rf=LaDigue_UHD.jpg&w=300&h=300&c=8&rs=1&o=3&r=0);
background-repeat: no-repeat;
background-position: center;
}
</style>
<div class="box"></div>
背景属性连写
<style>
.box {
width: 100%;
/* 元素必须给一个尺寸才能显示背景图 */
height: 500px;
/*
两种写法等价
background-color: #fff;
background-image: url(https://cn.bing.com/th?id=OHR.FanjingStairs_ZH-CN0360402048_UHD.jpg&rf=LaDigue_UHD.jpg&w=300&h=300&c=8&rs=1&o=3&r=0);
background-repeat: no-repeat;
background-position: center;
*/
background: #fff url(https://cn.bing.com/th?id=OHR.FanjingStairs_ZH-CN0360402048_UHD.jpg&rf=LaDigue_UHD.jpg&w=300&h=300&c=8&rs=1&o=3&r=0) no-repeat center;
}
</style>
<div class="box"></div>