score:2

you can use css max-height and @media queries to achieve this effect:

  • give the .stocks-container a max-height which corresponds with the height of a single grid row and declare overflow: hidden

this ensures that there will now only ever be a single row visible (ie. no vertical wrapping of rows).

  • now add a short series of break-point media queries to reset grid-template-columns as percentages of the viewport width.

this enables those grid boxes which are still visible to fill the entire horizontal width reserved for the .stocks-container.

working example:

.stocks-container {
display: grid;
grid-template-columns: repeat(5, calc(20% - 6px));
grid-template-rows: 92px;
grid-column-gap: 6px;
grid-row-gap: 6px;
max-height: 92px;
font-size: 11px;
overflow: hidden;
}

.stocks-container div {
height: 80px;
text-align: center;
border: 1px solid rgb(127, 127, 127);
}

@media only screen and (max-width: 900px) {

    .stocks-container {
    grid-template-columns: repeat(4, calc(25% - 6px));
    }
}

@media only screen and (max-width: 750px) {

    .stocks-container {
    grid-template-columns: repeat(3, calc(33.33% - 6px));
    }
}

@media only screen and (max-width: 600px) {

    .stocks-container {
    grid-template-columns: repeat(3, calc(50% - 6px));
    }
}
<div class="stocks-container">

<div>
<h2>company 1</h2>
<p>company stock</p>
</div>

<div>
<h2>company 2</h2>
<p>company stock</p>
</div>

<div>
<h2>company 3</h2>
<p>company stock</p>
</div>

<div>
<h2>company 4</h2>
<p>company stock</p>
</div>

<div>
<h2>company 5</h2>
<p>company stock</p>
</div>

</div>


Related Query

More Query from same tag