r9young / DECO7140-Final-Project

0 stars 0 forks source link

Bug - grid - .body-container #13

Open r9young opened 4 months ago

r9young commented 4 months ago

Issue: I'm experiencing an issue with my grid layout where I don't need the rows to divide the space into equal thirds automatically. Instead, I want each row to adjust its size based on its content. How can I achieve this?


.body-container {
    display: grid;
    grid-template-columns: auto;
    grid-template-rows: 1fr 1fr 1fr;
}
r9young commented 4 months ago

Solution:

If your goal is for the rows in your grid to adjust their size based on the content they contain, rather than each taking up exactly one-third of the available space, you should use auto instead of 1fr for the grid-template-rows property. This change makes each row size itself automatically to fit its content. Here’s how you can adjust your CSS:

.body-container {
    display: grid;
    grid-template-columns: auto; /* defines one column */
    grid-template-rows: auto auto auto; /* each row sizes to fit its content */
}

In this setup:

This configuration ensures that each row only uses as much vertical space as its content requires, making it flexible and content-responsive.