JavaScript 参考手册
Style backgroundOrigin 属性
相对于内容框定位背景图像
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> #myDIV { border: 1px solid black; width: 300px; height: 150px; padding: 35px; background: url("/examples/smiley.gif") no-repeat; } </style> </head> <body> <p>点击“尝试一下”按钮设置 DIV 元素的 background-origin 属性为 "content-box":</p> <button onclick="myFunction()">尝试一下</button> <div id="myDIV"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. </div> <script> function myFunction() { document.getElementById("myDIV").style.backgroundOrigin = "content-box"; } </script> </body> </html>
运行结果:
点击运行 »