Skip to main content
Inspiring
August 25, 2022
Question

CSS grid, how to avoid overwriting existing rules

  • August 25, 2022
  • 1 reply
  • 141 views

Some great person on here gave me code that produced a “product grid” in CSS grid:

 

.productGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr) ); 

grid-auto-rows: minmax(250px, auto); grid-gap: 10px; width: 90%; max-width: 1200px; margin: 0 auto; } 

.product { display: grid; place-content: center; border: 1px solid #999; }

 

I use it and like it very much. I do need another grid that has different attributes. I don’t want to overwrite the original rules. Would this additonal code, hoodGrid, work without overriding productGrid?:

 

.hoodGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr) ); 

grid-auto-rows: minmax(330px, auto); grid-gap: 10px; width: 90%; max-width: 1200px; margin: 0 auto; } 

.hoodProduct { display: grid; place-content: center; border: 0px; }

 

Thanks.

    This topic has been closed for replies.

    1 reply

    Legend
    August 25, 2022

    Thats fine, only the container/s with the .hoodGrid/hoodProduct classes assigned to it/them will take onboard the attributes declared in the .hoodGrid/hoodProduct css.