1)关键字:background-position: top left;
2)像素:background-position: 0px 0px;
3)百分比:background-position: 0% 0%;
上面这三句语句,都将图片定位在背景的左上角,表面上看效果是一样的,实际上第三种定位机制与前两种完全不同。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景偏移与定位</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.box{
height: 5000px;
background-image: url(../第七天/11/1.jpg);
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
}
.box1{
/*width: 1024px;*/
height: 1000px;
margin: 0 auto;
background-color: #bfa;
background-image: url(../第七天/11/1.jpg);
background-repeat: no-repeat;
/*background-position: -50px -50px;*/
background-attachment: fixed;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box"></div>
</body>
</html>
运行之后的结果