/    Sign up×
Community /Pin to ProfileBookmark

CSS Grid – Make Sibling Container Equal Heights?

Is it possible to make the .title div equal heights with CSS Grid? The text will be of variable length and needs to be shown in full ( no overflow hidden) but I cant work out if its possible to make the title divs equal height with CSS Grid?

CSS:

“`
.container {
max-width: 120rem;
margin: 0 auto;
padding: 1rem;
}
.row {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(1, 1fr); /* mobile screens – single column */
grid-auto-rows: auto;
}
.box {
color: #fff;
font-family: “Gill Sans”, “Gill Sans MT”, “Myriad Pro”, “DejaVu Sans Condensed”, Helvetica, Arial, “sans-serif”;
font-size: 1.2rem;
text-align: center;
}
.title {
border-radius: 0.75rem 0.75rem 0 0;
}
.title, .price {
background-color: #22275B;
padding: 0.75rem;
}
.image {
border: 2px solid #22275B;
}
.image img {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
}
.saving {
background-color: #A81E22;
padding: 0.75rem;
border-radius: 0 0 0.75rem 0.75rem;
}
@media only screen and (min-width: 660px) { /* tablets portrait */

.row {
grid-template-columns: repeat(2, 1fr); /* tablet portrait – 2 columns */
}
}
@media only screen and (min-width: 900px) { /* tablets landscape */

.row {
grid-template-columns: repeat(3, 1fr); /* tablet landscape – 3 columns */
}
}
@media only screen and (min-width: 900px) { /* tablets landscape */

.row {
grid-template-columns: repeat(3, 1fr); /* tablet landscape – 3 columns*/
}
}
@media only screen and (min-width: 1200px) { /* desktops */

.row {
grid-template-columns: repeat(4, 1fr); /* desktops – 4 columns */
}
}
“`

HTML:

“`
<div class=”container”>
<div class=”row”>
<div class=”box”>
<div class=”title”>Here Is A Very Very Very Very Very Very Very Very Very Very Very Very v v Very Very Very Very Very Very v Very Very Very Very Very Very Very Very Very Very Looong Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
<div class=”box”>
<div class=”title”>Here Is A Title</div>
<div class=”image”><img src=”//placehold.it/5000×3000″ width=”500″ height=”300″ alt=”” />
</div>
<div class=”price”>PRICE £999.00</div>
<div class=”saving”> SAVE £99.00 OFF RRP</div>
</div>
</div>
</div>“`

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@energylevelsauthorApr 14.2021 — To anser by own question I updated the .box class rules as follows:

.box {<br/>
color: #fff;<br/>
font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, "sans-serif";<br/>
font-size: 1.2rem;<br/>
text-align: center;<br/>
display: grid;<br/>
grid-template-columns: repeat(1, 1fr);<br/>
grid-template-rows: 1fr auto auto auto;<br/>
grid-gap: 0;<br/>
}


grid-template-rows ''auto' fits content and 1fr fills the remaining space
Copy linkTweet thisAlerts:
@SempervivumApr 15.2021 — Fine that you found a solution on your own. For future posts please note:

Single backtics don't work reliably when posting code. You better use code tags: `your code here` or triple backtics.

I edited your posting accordingly.
Copy linkTweet thisAlerts:
@inktApr 15.2021 — A library makes is much easier on you. Bootstrap is your friend.
Copy linkTweet thisAlerts:
@SempervivumApr 15.2021 — @inkt#1630401 I do [b]not[/b] agree. Bootstrap is obsolete overhead and outdated. At times when

grid and flex layout were not available it was a workaround for creating responsive layouts. But times have changed, both are available now and any layout you require can be created by use of them.
Copy linkTweet thisAlerts:
@cootheadApr 15.2021 — > @inkt#1630401 Bootstrap is your friend.

[i]Au contraire[/i], Bootstrap is their arch enemy and

should be avoided like the plague.

[i]coothead[/i]
Copy linkTweet thisAlerts:
@inktApr 15.2021 — @Sempervivum#1630403 Bootstrap is far from obsolete, it uses current technologies, and expanding on them. Adding a some &lt;div&gt;s with classes, is MUCH less less work than doing it yourself. Besides there are tonnes of additions that justify it. Sure you can develop your own form stying, or create your own modal, but life is way easier if you use one that is already developed. Bootstrap lets you pick the components to add, so its overhead is up to the website creator. As far as your outdated comment, that is just not true either, its constantly getting additions and updates, very recently too.
Copy linkTweet thisAlerts:
@cootheadApr 15.2021 — Hi there inkt,

is [b]Bootcrap[/b] paying you commission to spout that nonsense?

[i]coothead[/i]
×

Success!

Help @energylevels spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...