Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I change the size of grid cells to better fit its content?

As you can see the content inside the grid cell does not fit the size of the grid cell. I am trying to change the size of the grid cell to better fit the content inside.

This is the code responsible for the grid:

main {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(589.19px, 1fr));
    overflow-x: hidden;
    justify-items: center;
    align-items: center;
}

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Currently your property grid-template-columns: repeat(auto-fit, minmax(589.19px, 1fr));, specifically auto-fit ensures the grid fills the space and doesn’t leave empty space in the line.
You can use:
grid-template-columns: repeat(2, minmax(589.19px, min-content)); and in case 589.19px is too wide for you maybe repeat(2, min-content) will work better.

The repeat function takes two arguments the first one is the repeat count. When set to auto-fit it repeats until the line is filled, if you set two 2 you repeat it twice.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading