I'm building a grid layout using CSS Grid and I want all my columns to have the same size (fixed sized) and that size being the one of the largest column.
I know that I can do it using JS or even display: table
but I would like to do it using CSS Grid (if it's possible).
Here's what I have:
* {
box-sizing: border-box;
}
div {
display: grid;
grid-template-columns: repeat(auto-fit, 120px);
gap: 5px;
}
span {
padding: 10px;
border: 1px solid black;
}
<div>
<span>Orange</span>
<span>Purple</span>
<span>Aquamarine</span>
<span>Black</span>
<span>Brown</span>
<span>Red</span>
</div>
I fixed the width at 120px but I want that width to be the one of Aquamarine which is the largest one.