this post was submitted on 09 Sep 2025
8 points (100.0% liked)

CSS

755 readers
11 users here now

founded 2 years ago
MODERATORS
 

Hello everyone good to see there's a CSS community so it's time to start trying to break stuff.

Basically I am a Grid novice who has the classic HTML grid example:

<div class="grid">

  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
  ...
</div>

For which I've posted a codepen.

My problem is, I want to make it so that the number of columns adjusts as multiples of a given basis I want. Basically I'd expect this part to have worked:


div.grid.notworks {
  grid-template-columns: repeat(3n, 90px); /* :( */
}

(note the 3n, not 3; like in eg.: nth-child)

Such that the container will reflow itself to host 3, 6, 9, 12, ... columns rather than 1, 2, 3, ... (as it would be on flex) or only specifically 3, as it would be with (what I understand is) the normal repeat expression in div.grid.works.

Is this possible in CSS? If yes: teach me your CSS and Firefox secrets senpai. If not: is this planned / requested?

Tags in case this helps? I hear this is the trend in the fediverse. #css #grid-layout

you are viewing a single comment's thread
view the rest of the comments
[โ€“] veniasilente@lemmy.dbzer0.com 2 points 6 months ago (1 children)

Setting several media queries for div.grid.works to set its width in multiples of 90px * n;

Just to check: wouldn't that have to be container queries? Media queries IIRC can only tell me the size of the browser viewport, but not how much screen state is lost to eg.: toolbars, floats, other containers, margins, etc... so that could easily lead to container overflow.

All that said, I hope this is implemented soon (would love to know how to make a feature request to ~~W3C, bunch o'DRM assholes~~ Firefox) since in theory if it was supported as a declaration natively the engine would take care of accounting for grid gap, etc.

[โ€“] mmmm@sopuli.xyz 2 points 6 months ago

Oh yes my bad, I meant container queries (it's that I always think about the @media screen and (min|max-width=<width>px)