Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Child blocks and parent borders(Grid-Layout)

Why do child blocks (block) go beyond the boundaries of the parent block (child_block)?
I would like child blocks to automatically wrap to a new line

How to achieve the result as in the screenshot:
enter image description here

let main = document.querySelector('.main_block');
let child_block = document.querySelector('.child_block');
            
for(let i = 0; i < 50; i++){
let xep = document.createElement('div'); 
child_block.prepend(xep);
xep.className = 'block';
xep.innerHTML = 'Xopa'
}
.main_block{
display:grid;
grid-template-columns: 100%; 
padding:10px;
margin:50px;
border:1px solid black;
}

.child_block{
display:grid;
grid-auto-flow: column;
}

.block{
display: inline-block;  
border:1px solid black;
font-size:18px;
padding:10px;
}
<div class = "main_block">

<div class = "child_block">


</div>

</div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use flex instead of grid simply

let main = document.querySelector('.main_block');
let child_block = document.querySelector('.child_block');
            
for(let i = 0; i < 50; i++){
let xep = document.createElement('div'); 
child_block.prepend(xep);
xep.className = 'block';
xep.innerHTML = 'Xopa'
}
.main_block{
display:grid;
grid-template-columns: 100%; 
padding:10px;
margin:50px;
border:1px solid black;
}

.child_block{
display:flex;
flex-wrap: wrap;
}

.block{
display: inline-block;  
border:1px solid black;
font-size:18px;
padding:10px;
}
<div class = "main_block">

<div class = "child_block">


</div>

</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading