CSS Grid Minmax() With Max-width Of 100%
This code uses CSS grid with minmax(30rem, 1fr). grid-template-columns: repeat(auto-fill, minmax(30rem, 1fr)); Everything works fine, but when the viewport parent container gets s
Solution 1:
Sounds like you have a breakpoint when the screen width is 30rem
. That calls for a media query.
Add this to your code:
@media (max-width: 30rem) {
ul { grid-template-columns: 1fr; }
}
ul {
list-style-type: none;
padding: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(30rem, 1fr));
grid-auto-rows: 1fr;
grid-gap: 10px;
}
li {
background-color: #aaa;
padding: 0.5rem;
}
@media (max-width: 30rem) {
ul {
grid-template-columns: 1fr;
}
}
<ul class="list">
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<li>grid item</li>
<ul>
Post a Comment for "CSS Grid Minmax() With Max-width Of 100%"