I have a grid that draws squares in cells. It has the number of rows and columns, then draws the grid cells and checks if there should be a square in each cell (according to the array) and draws a square if needed. The HTML final result looks like this: (assuming I have 1 row and 3 columns, only 2 cells should have squares)
.row { display: flex; flex-wrap: wrap; flex: 10000 1 0%; } .column { display: flex; flex-wrap: wrap; max-width: 100px; min-width: 10px; padding: 4px; border: 1px solid grey; } .square { background-color: red; width: 100%; aspect-ratio: 1/1; border-radius: 5px; }
<div class="row"> <div class="column"> <div class="square"></div> </div> <div class="column"> <div class="square"></div> </div> <div class="column"></div> </div>
The rows take up the entire width of the screen and the column sizes should be the same between all columns and change based on the number of columns on the screen (for example if I have 5 columns they should all come with a width of 100 pixels but if I have 1000 columns and they should all be 10 pixels wide).
My problem is that the padding and border radius look weird after a certain breakpoint in the column size, and I want to change their values when I hit that breakpoint. I can't use @container queries because it's still not fully supported.
If it helps, I'm using vue 2. But I think a CSS solution would be better in this case.
Attempt to solve the problem described:
I made a small demo to help me better explore the conditions for achieving this scenario.
Get border:collapse equivalent on flexbox item
The.row
element is still a Flexbox container, but its Flex item does not haveborder
set, but uses theoutline
setting for styling.The outline takes up no space and will "collapse" when colliding with the outline generated by another element.
So, to ensure that the layout is not affected by styling weirdness, when trying to display the borders of a Flex item, this demo relies on only 2 key aspects to render those borders:
gap between flexible items
Outline
size to cover the gap left between elementUse ::after to add content to an element
Additionally, the red dot is applied as a
::after
pseudo-element withposition:absolute
, again ensuring that nothing affects the grid layout:Dashboard - Explore Options
From there, I added a "dashboard" with
position:fixed
which stays at the top of the page and allows you to control:display: none;
will not change the grid layout it depends entirely on.column
element sizeset by custom variable
--col-widthConclusion so far:
Although we have worked hard to minimize distractions and taken all the steps needed to correctly set up the grid layout based only on the fixed size of the cells , there are still some issues Rendering issues, sometimes a general mismatch pattern in border sizes for certain lines. I should say that I only have issues with my laptop display, not my desktop monitor, so that's another factor.
I tried different parameters and crunched the numbers in the demo, taking the gaps into account as well. A good and safe layout can minimize potential problems (for example, it can also increase the border size).
I couldn't get any further than this using Flex layout.