二、实践:
1.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> div { width: 300px; height: 200px; border: 20px dashed rgba(0,0,0,0.5); background: orchid url(images/border-background.gif) no-repeat left top; padding: 20px; margin: 30px; } .padding-box{ -webkit-background-origin: padding-box; -moz-background-origin: padding-box; -o-background-origin: padding-box; -ms-background-origin: padding-box; background-origin: padding-box; } .padding-box1{ -webkit-background-origin: border-box; -moz-background-origin: border-box; -o-background-origin: border-box; -ms-background-origin: border-box; background-origin: border-box; } .padding-box2{ -webkit-background-origin: content-box; -moz-background-origin: content-box; -o-background-origin: content-box; -ms-background-origin: content-box; background-origin: content-box; } </style> </head> <body> <div >1</div> <div class="padding-box" >2</div> <div class="padding-box1" >3</div> <div class="padding-box2" >5</div> </body> </html>2.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> div { width: 300px; height:600px; border:50px dash rgba(0,0,0,0.8); background: rgba(0,25,25,0.8) url(images/2-11-test.jpg) no-repeat; padding: 30px; margin: 20px; } .no-repeat{ background-repeat: no-repeat; } .repeat{ background-repeat: repeat; } </style> </head> <body> <div class = "no-repeat"></div> <div class="repeat"></div> </body> </html>3.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> div { width: 300px; height:300px; border:30px dashed rgba(25,25,125,0.5); background: url(images/2-11-test.jpg) no-repeat; margin: 20px; padding: 30px; } .border-box{ -webkit-background-clip: border-box; -moz-background-clip: border-box; -o-background-clip:border-box; -ms-background-clip:border-box; background-clip: border-box; } .border-box{ -webkit-background-clip: padding-box; -moz-background-clip: padding-box; -o-background-clip:padding-box; -ms-background-clip:padding-box; background-clip: padding-box; } .content-box{ -webkit-background-clip: content-box; -moz-background-clip: content-box; -o-background-clip:content-box; -ms-background-clip:content-box; background-clip: content-box; } </style> </head> <body> <div class="border-box"></div> <div class="padding-box"></div> <div class="content-box"></div> </body> </html>