<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box1{
overflow: auto;
width: 500px;
height: 500px;
background-color: #bfa;
background-image: url("./img/3.png");
background-repeat: no-repeat;
background-position: 0 0;
border: 10px red double;
padding: 10px;
/*
background-clip 设置背景的范围
可选值
border-box 默认值 背景会出现在边框的下边
padding-box 背景不会出现在边框的下边,而只出现在内容区和内边距
content-box 背景只会出现在内容区
background-origin 背景图片的偏移量计算的原点
可选值
padding-box 默认值 background-position从内边距开始计算
content-box 背景图片的偏移量从内容区处计算
border-box 背景图片的偏移量从边框处计算
*/
background-origin: border-box;
background-clip: content-box;
/*
background-size 设置背景图片的大小
可选值
- 第一个值表示宽度,第二个值表示高度
- 如果只写一个值,则第二个值默认是auto(等比例缩放)
- cover 图片的比例不变,将元素铺满
- contain 图片比例不变,将图片在元素中完整显示
*/
background-size: contain;
/*
background-color
background-image
background-repeat
background-position
background-size
background-origin
background-clip
background-attachment
- background 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
并且该样式没有顺序要求,也没有哪个属性是必须写的
注意:
background-size必须写在background-position的后边,并且要用斜杠隔开
background-position/background-size
background-origin必须写在background-clip的前边
*/
}
.box2{
width: 300px;
height: 1000px;
/* background-color: orange; */
background-image: url("./img/2.png");
background-repeat: no-repeat;
/*
background-attachment设置背景图片是否跟随元素移动
可选值
- scroll 默认值 背景图片会跟随元素移动
- fixed 表示背景图片会固定在页面中,不会随着元素移动
(结合固定定位position:fixed;理解)
*/
background-attachment: fixed;
background-position: 100px 100px;
}
.box3{
padding: 50px;
border: 10px red double;
width: 500px;
height: 500px;
/*
background-size必须在background-position的后边(用斜杠隔开)
background-origin必须写在background-clip的前边
*/
background: #bfa url("./img/2.png") center center/contain content-box content-box no-repeat;
}
</style>
</head>
<body>
<!-- <div class="box3"></div> -->
<div class="box1">
<div class="box2">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum esse dolorum quas ab, saepe necessitatibus asperiores laudantium fugiat animi repellat neque delectus voluptas rem non veritatis quaerat. Quod, eaque nesciunt?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Officiis id, rem enim et voluptates dolor quas laborum odio labore praesentium odit laudantium vel, veritatis ex! Doloremque consequuntur totam praesentium repudiandae?
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quos id repellat facilis fugiat quis earum voluptatibus commodi ab animi saepe eos dicta odio voluptate reiciendis, velit illo, quo sunt in.
</div>
</div>
</body>
</html>