运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 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> <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>