I have a child div which is a css gird (that is being created by js which will change on users input)that i want to fit 100% according to the parent divs fixed height and width. How do I proceed with this?
.container is the parent div here. I want it to be a fixed size and the .grid-container to fit according to .containers size
var count = 32;
for (var i = 0; i < count; i++) {
const container = document.querySelector('#grid-container');
const content = document.createElement('div');
content.classList.add('grid-item');
container.appendChild(content);
}
.grid-item {
background-color: rgb(255, 255, 255);
border: 1px solid rgba(0, 0, 0, 0.8);
padding: 20px;
}
.grid-container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(auto-fill);
height: 100%;
}
.container {
width: 400px;
height: 400px;
border: 15px solid green;
}
<div class="container">
<div class="grid-container" id="grid-container">
</div>
</div>
If i get you right simple change the container width and/or height values from "fixed" pixels to percents ...
.container{
width: 100%;
height: 100%;
border: 15px solid green;
}