运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> #container { width: 100%; aspect-ratio: 2; margin: 10px 0; border: solid black 1px; display: grid; grid-template-columns: 1fr 1fr 1fr; } #container > div { width: 50%; aspect-ratio: 2; margin: 2px; background-color: coral; } </style> </head> <body> <h1>Change place-items property with JavaScript</h1> <p>Click the "Try it" button to change the place-items value of the grid container:</p> <button onclick="myFunction()">Try it</button> <div id="container"></div> <script> function myFunction() { document.getElementById("container").style.placeItems = "stretch center"; } let containerEl = document.getElementById("container"); for(let i=0; i<8; i++){ let divEl = document.createElement("div"); containerEl.appendChild(divEl); } </script> </body> </html>