一、背景图像固定
background-attachment属性设置背景图像是否固定或者随着页面的其余部分滚动
1. 语法
background-attachment: scroll | fixed
2. 参数
- scroll : 滚动
- fixed : 固定
二、背景复合写法
简写属性时, 没有固定的书写顺序.
div {
width: 1920px;
height: 1100px;
background: red url(./images/bg.jpg) no-repeat fixed center 40px;
}
三、背景色半透明
1. 语法
background: rgba(0, 0, 0, 0.3);
可以把 0.3 的 0 省略 , 写成 .3 也是支持的
四、案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.nav a {
display: inline-block;
width: 120px;
height: 58px;
text-align: center;
text-decoration: none;
line-height: 48px;
color: white;
}
.bg1 {
background-image: url(./images/bg1.png);
}
.bg2 {
background-image: url(./images/bg2.png);
}
.bg3 {
background-image: url(./images/bg3.png);
}
.bg4 {
background-image: url(./images/bg4.png);
}
.bg1:hover {
background-image: url(./images/bg11.png);
}
.bg2:hover {
background-image: url(./images/bg22.png);
}
.bg3:hover {
background-image: url(./images/bg1.png);
}
.bg4:hover {
background-image: url(./images/bg2.png);
}
</style>
</head>
<body>
<div class="nav">
<a href="" class="bg1">五彩导航</a>
<a href="" class="bg2">五彩导航</a>
<a href="" class="bg3">五彩导航</a>
<a href="" class="bg4">五彩导航</a>
</div>
</body>
</html>