本节介绍css的背景属性以及应用效果css常用的背景属性背景应用css3新增背景属性css常用背景属性css中的背景是由background属性来设置背景的,它是一个综合属性,可以拆分为单一的属性背景
顺晟科技
2021-08-04 11:12:37
80
| 值 | 描述 | scroll 背景图片随着页面的滚动而滚动,这是默认的。并不随着div内的滚动而滚动(比如文本大于元素高度时的滚动,背景图不动) fixed 背景图片不会随着元素或页面的滚动而滚动。 local 背景图片会随着元素或页面的滚动而滚动。 initial 表示默认值。 inherit 表继承
|---|
写HTML ,当背景图片大于元素高度时,设置background-attachment:fixed; 当页面滚动,当前元素就可以得到不一样的背景图,很好看。
<!DOCTYPE html>
<html lang="cn">
<head>
<title>移动</title>
<mate charset="UTF-8">
</head>
<style>
body{
padding: 0;
margin: 0;
font-family:Raleway,Helvetica,arial;
}
#bg-img{
background-image: url("/uploads/image/20210804/home_paralax2.jpg");
background-position: center center;
background-attachment: fixed;
background-repeat: no-repeat;
background-size: cover;
transition: background 0.3s, border 0.3s, border-radius 0.3s, box-shadow 0.3s;
padding: 121px 0px 120px 0px;
position: relative;
}
#bg-img::after{
content: " ";
height: ;
width: ;
top: 0;
left: 0;
position: absolute;
background-color: #000000;
opacity: 0.65;
z-index: 1;
}
.empty{
height: 800px;
background-color: bisque;
}
#bg-img ul{
padding:20px;
margin: 0;
position: relative;
z-index: 2;
}
#bg-img li{
line-height: 30px;
list-style-type: none;
text-align: center;
color: #fff;
}
</style>
<body>
<div class="empty">
空
</div>
<section id="bg-img">
<ul>
<li>Need fresh and classy design? </li>
<li>We are here to offer you the most unique and classy solutions! Every design idea and project we perform,</li>
<li>completely meet our clients\' requirements being at the same time creative and extraordinary.</li>
<li>Read more</li>
</ul>
</section>
<div class="empty">
空
</div>
</body>
</html>
07
2022-10
15
2022-09
15
2022-09
15
2022-09
14
2022-09
14
2022-09