CSS3新增背景属性
1 background-origin
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>background-origin</title>
<style>
div {
height: 400px;
width: 400px;
padding: 30px;
border: 20px dashed red;
background-color: darkkhaki;
margin: 0 auto;
background-image: url("../../1、CSS选择器/imgs/fengjing.png");
background-repeat: no-repeat;
background-origin: content-box;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
1 background-clip
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>background-clip</title>
<style>
div {
height: 400px;
width: 400px;
padding: 30px;
border: 20px dashed red;
background-color: black;
margin: 0 auto;
background-image: url("../images/bg.jpg");
background-repeat: no-repeat;
background-origin: padding-box;
font-size: 100px;
text-align: center;
line-height: 400px;
color: transparent;
background-clip: content-box;
}
</style>
</style>
</head>
<body>
<div>文字</div>
</body>
</html>
3 background-size
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>background-size</title>
<style>
div {
height: 400px;
width: 400px;
border: 1px solid black;
background-image: url("../images/bg.jpg");
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
4 background复合属性
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>background-origin</title>
<style>
div {
height: 400px;
width: 400px;
padding: 30px;
border: 20px dashed red;
margin: 0 auto;
background: rgb(146, 97, 97) url("../images/bg.jpg") 5px 5px / 100% 100% border-box content-box;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
5 多背景图
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>多背景图</title>
<style>
div {
height: 400px;
width: 400px;
border: 1px solid black;
background: url("../images/touxiang.png") no-repeat top left/ 20% 20%,
url("../images/touxiang.png") no-repeat top right/ 20% 20%,
url("../images/touxiang.png") no-repeat bottom left/ 20% 20%,
url("../images/touxiang.png") no-repeat bottom right/ 20% 20%;
}
</style>
</head>
<body>
<div></div>
</body>
</html>