作用:将背景图片放置在合适的位置上。
格式:background-position: 水平方向位置 垂直方向位置;
水平取值:left、center、right;
垂直取值:top、center、bottom;
除此之外,取值还可以具体化,例如:100px;取值可以取负值,代表离开页面的长度。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>标题</title>
<style>
.c1 {
height: 300px;
background-image: url(11.jpg);
background-repeat: no-repeat;
background-position: center center;
}
.c2 {
height: 300px;
background-image: url(11.jpg);
background-color: red;
background-repeat: no-repeat;
background-position: 100px 50px;
}
</style>
</head>
<body>
<div class="c1">
1111
</div>
<div class="c2">
2222
</div>
</body>
</html>