<!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);
}