I have a list of 8 results that I render in the responsive bootstrap grid. I would like it to cut the results that do not fill in the whole row.
So, for example, right now, on a middle-size screen, it is shown as 2 rows with 4 results each, but on the smaller screen, it would be 2 rows with 2 results in each and the last row with 2 only. I would like only the first two full rows to be displayed.
How can I tell the bootstrap not to show the last row?
let frag = '';
for (let i = 0; i < 8; i++) {
frag += `
<div class="myElem">
<div class="content">
<p>Lorem ipsum...</p>
</div>
</div>
`
}
$("#myDiv").html(frag);
.myElem {
position: relative;
width: 200px !important;
margin-bottom: 1rem;
}
.content {
width: 100%;
height: 100%;
background-color: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row myDiv" id="myDiv">
</div>
2
Answers
First, you need to update your for loop and add the appropriate Bootstrap grid classes to your myElem divs. Then, you can use media queries in your CSS to hide the elements on smaller screens.
Your frag layout is without bootstrap classes. So they don’t fit the grid you started with "row". with bootstrap classes it would look something like that.
So you have one row and many columns in it and you can use the display classes to controll them. like
.d-md-none
to hide it on the md breakpoint