background-origin: 背景图片从盒子哪里开始渲染
background-clip: 背景图片裁剪到盒子哪里css
background-origin:html
默认值:背景图片从padding区域开始渲染
boder-box: 背景图片从边框里面开始
padding-box:背景图片从padding区域开始渲染
content-box: 背景图片从内容区域开始渲染学习
background-clip:url
默认值: 背景图片裁剪到padding区域最外层边缘线
boder-box: 背景图片裁剪到边框最外层边缘线
padding-box: 背景图片裁剪到padding区域最外层边缘线
content-box: 背景图片裁剪到内容区域最外层边缘线spa
咱们在使用背景图片时,确定首先是要确认咱们的背景图片要从哪里开始渲染,
肯定了渲染的状态, 咱们才能准确的对背景图片进行裁剪。固然背景图片默认的渲染状态是从padding
区域开始渲染的,咱们在没有确认渲染的区域时,后期所作的裁剪工做实际上都是对照默认渲染区padding
区域来进行裁剪的。code
background-origin:htm
代码:blog
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> .box,.box1,.box2,.box3 { width: 200px; height: 200px; border: 20px dotted #ccc; padding: 30px; background: url('images/bg.png') no-repeat; background-size: 100% 100%; margin-top: 50px; } .box1 { background-origin:border-box; } .box2 { background-origin: content-box; } .box3 { background-origin: padding-box; } </style> </head> <body> <div class="box"></div> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </body> </html>
图片:图片
background-clip:ip
代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> .box,.box1,.box2,.box3 { width: 200px; height: 200px; border: 20px dotted #ccc; padding: 30px; background: url('images/bg.png') no-repeat; background-size: 100% 100%; margin-top: 50px; } .box1 { background-clip: border-box; } .box2 { background-clip: content-box; } .box3 { background-clip: padding-box; } </style> </head> <body> <div class="box"></div> <div class="box1"></div> <div class="box2"></div> <div class="box3"></div> </body> </html>
图片:
以上就是对background-origin和background-clip的解述,咱们在裁剪背景图片作某些效果时就必定得准确的先渲染。若是以上那些地方理解有误还请指点,笔者会虚心学习。