运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> #myDIV { border: 1px solid black; background-color: lightblue; width: 300px; height: 300px; position: relative; top: 20px; } </style> </head> <body> <h1>Change position with JavaScript</h1> <p>Click the "Try it" button to change the position property of the DIV element:</p> <button onclick="myFunction()">Try it</button> <div id="myDIV"> <p>This DIV element is placed 20 pixels from the top of its original position.</p> <p>Click the button to set the position property to "absolute" and see what happens.</p> <p>It will then be placed 20 pixels from the top the page.</p> </div> <script> function myFunction() { document.getElementById("myDIV").style.position = "absolute"; } </script> </body> </html>