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的解述,咱們在裁剪背景圖片作某些效果時就必定得準確的先渲染。若是以上那些地方理解有誤還請指點,筆者會虛心學習。