运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往Spaces
<!DOCTYPE html> <html> <head> <style> #container { width: 100%; aspect-ratio: 1; margin: 10px 0; border: solid black 1px; display: grid; grid-template-columns: repeat(3,1fr); place-items: start; } #container > div { padding: 20%; margin: 2px; } .normal { background-color: lightblue; } #myDiv { background-color: coral; } </style> </head> <body> <h1>Change place-self property with JavaScript</h1> <p>Click the "Try it" button to change the place-self value of the orange grid item:</p> <button onclick="myFunction()">Try it</button> <div id="container"> <div class="normal"></div> <div class="normal"></div> <div class="normal"></div> <div class="normal"></div> <div class="normal"></div> <div id="myDiv"></div> <div class="normal"></div> <div class="normal"></div> <div class="normal"></div> <div class="normal"></div> </div> <script> function myFunction() { document.getElementById("myDiv").style.placeSelf = "end stretch"; } </script> </body> </html>