前端学习之CSS3
一、CSS3背景新增内容
1.background-clip
background-clip:背景的绘制区域。
语法:
background-clip: border-box | padding-box | content-box;
示例:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style type="text/css">
.test{
width: 300px;
height: 100px;
padding: 50px;
border: 20px dashed red;
background-color: #00FFFF;
background-clip: border-box;/*border-box也是默认值*/
}
</style>
</head>
<body>
<div class="test"></div>
</body>
</html>
结果:
当值为padding-box时:
<style type="text/css">
.test{
width: 300px;
height: 100px;
padding: 50px;
border: 20px dashed red;
background-color: #00FFFF;
background-clip: padding-box;
}
</style>
当值为content-box时:
<style type="text/css">
.test{
width: 300px;
height: 100px;
padding: 50px;
border: 20px dashed red;
background-color: #00FFFF;
background-clip: content-box;
}
</style>
结果:
2.background-origin
background-origin:背景图片的定位区域。
语法同background-clip一样,定位默认值是padding-box,示例:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style type="text/css">
.test{
width: 300px;
height: 100px;
padding: 50px;
border: 20px dashed red;
background-color: #00FFFF;
background-image: url(../img/csdn.png);
background-repeat: no-repeat;
/* background-origin: padding-box; */
}
</style>
</head>
<body>
<div class="test"></div>
</body>
</html>
结果:
当值为border-box时:
<style type="text/css">
.test{
width: 300px;
height: 100px;
padding: 50px;
border: 20px dashed red;
background-color: #00FFFF;
background-image: url(../img/csdn.png);
background-repeat: no-repeat;
background-origin: border-box;
}
</style>
结果:
当值为content-box时:
<style type