运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到空间
<!DOCTYPE html> <html> <head> <style> #myDIV { border: 1px solid black; width: 300px; height: 250px; background: url('w3css.gif') no-repeat; } </style> </head> <body> <h1>Change background-position-x with JavaScript</h1> <p>Click the "Try it" button to set the background-position-x property of the DIV element to "center":</p> <button onclick="myFunction()">Try it</button> <div id="myDIV"> <h1>Hello</h1> </div> <script> function myFunction() { document.getElementById("myDIV").style.backgroundPositionX = "center"; } </script> </body> </html>