Been trying to make a fancy new website and came across this – the other divs are resizing when content is added.
How it should look: A rectangle divided into 2 thirds, with one double the size of the other.
How it looks: A rectangle divided into 2 fifths, with one quadruple the size of the other containing text:
Nothing else I found online works. CSS code below if it matters.
/* basic styling above */
#container {
display: grid;
grid-template-areas:
"🟥 🟥 🟨";
height: 600px;
}
#work {
grid-area: 🟥;
}
#thing {
grid-area: 🟨;
}
Already fixed thanks to Hao Wu. (Editing for discovery purposes)
All I needed was css grid-auto-columns: 1fr
2
Answers
You didn’t specify the proportion for each column. If you want the
🟥
area to take 2/3 of the space, try addinggrid-auto-columns: 1fr
to your grid layout. So all the columns are taking the equal spaces.The default width of a column in a grid is
auto
. That means the grid column will expand or shrink if needed.To have a 2:1 split you should use:
grid-template-columns: 2fr 1fr
which will split the columns equally in 2 fractions and 1 fraction.