Although I have not yet been able to find an answer, the question is simple: Is there a way, other than brute force, to count the number of columns in a responsive grid?
#grid-container {
width: 100%;
height: 85%;
position: relative;
padding: var(--gap); /* adjusted with JS to make var(--gap) responsive */
display: grid;
grid-gap: var(--gap); /* adjusted with JS to make var(--gap) responsive */
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
box-sizing: border-box;
background: skyblue;
}
.grid-item {
width: 100%;
min-width: 120px;
max-width: 450px;
height: ; /* adjusted with JS on resize events to roughly maintain proportions */
min-height: 192px;
border-radius: 10px;
background: #333;
}
The reason I ask is because I have given the grid items a max-width
that causes a massive gap at the very last breakpoint, which I would like to be able to detect instead of setting an explicit media query.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…