Grid gap having uneven gaps

So this is this grid wrapper:
<div className={styles.boxWrapper}> {boxElements && boxElements.map((box) => box)} </div> here is each box element jsx: (boxelements is nothing but array of these : <div key={index} className={${styles.box} ${boxClass}} /> ) css: .boxWrapper { display: grid; grid-template-columns: repeat(53, max-content); gap: 2px 2px; } .box { width: 10px; height: 10px; background-color: white; }` idk what is causing this, any help would be appreciated
No description
8 Replies
MarkBoots
MarkBoots•8mo ago
this probably has to do with rounding. with so many columns, the width of each probably doesnt round to a full pixel.
Jus Sus || 💀
Jus Sus || 💀OP•8mo ago
Is there a way to fix this, or other option would be to go with flex box?
MarkBoots
MarkBoots•8mo ago
instead of max-content, you can set it to 10px and have a grid-auto-rows of 10px. then you don't need it on the boxes https://codepen.io/MarkBoots/pen/oNOMjzY
Jus Sus || 💀
Jus Sus || 💀OP•8mo ago
This is working in codesandbox, but idk whats happening in my local system. maybe i need to resetup my project again
MarkBoots
MarkBoots•8mo ago
maybe the content is exceeding the size of the box? insepect element
Jus Sus || 💀
Jus Sus || 💀OP•8mo ago
It was vite issue, idk what specifically, but when i create a new vite app the issue was still there but when i changed to create-react-app , it went away Oh no, sorry it wasnt vite or CRA's issue. the grip gap is uneven in firefox, but it renders fine in chrome and other browser
capt_uhu
capt_uhu•8mo ago
if it's just a Firefox issue maybe the new round() function can help?: https://developer.mozilla.org/en-US/docs/Web/CSS/round
MDN Web Docs
round() - CSS: Cascading Style Sheets | MDN
The round() CSS function returns a rounded number based on a selected rounding strategy.
Chris Bolson
Chris Bolson•8mo ago
I don't know your use case, but, if you are not putting any contents in the grid boxes, you might consider doing this with a linear-gradient background.
Want results from more Discord servers?
Add your server