Reputation:
I'd like to achieve the following effect:
.wrap {
display: grid;
grid-template: 2rem 10rem / auto 20rem auto;
}
.a {
background: orange;
grid-column: 1 / 4;
grid-row: 1;
}
.b {
background: green;
grid-column: 2;
grid-row: 1;
}
.c {
background: lightblue;
grid-column: 1 / 4;
grid-row: 2;
}
<div class="wrap">
<div class="a"></div>
<div class="b">Title</div>
<div class="c">This is section C.</div>
</div>
but using the following HTML instead:
<div class="wrap">
<div class="a"><div class="b">Title</div></div>
<div class="c">This is section C.</div>
</div>
where .b
is inside .a
.
In other words, I'd like for element .a
to occupy the top row of a CSS grid, but have one of its subelements, .b
, to occupy only the middle cell of this same CSS grid row. Is this possible?
Upvotes: 1
Views: 376
Reputation: 2260
That will work just fine in the future by defining display: subgrid in class .a... But support is still very limited. https://gridbyexample.com/video/subgrid-display-contents/
.wrap {
display: grid;
grid-template: 2rem 10rem / auto 20rem auto;
}
.a {
background: orange;
grid-column: 1 / 4;
grid-row: 1;
display: subgrid;
}
.b {
background: green;
grid-column: 2;
grid-row: 1;
}
.c {
background: lightblue;
grid-column: 1 / 4;
grid-row: 2;
}
<div class="wrap">
<div class="a">
<div class="b">Title</div></div>
<div class="c">This is section C.</div>
</div>
Upvotes: 0
Reputation: 5544
Apply display:grid
and grid-template: 2rem 10rem / auto 20rem auto;
to a
, check this
.wrap {
display: grid;
grid-template: 2rem 10rem / auto 20rem auto;
}
.a {
background: orange;
grid-column: 1 / 4;
grid-row: 1;
display: grid;
grid-template: 2rem 10rem / auto 20rem auto;
}
.b {
background: green;
grid-column: 2/ 3;
grid-row: 1;
}
.c {
background: lightblue;
grid-column: 1 / 4;
grid-row: 2;
}
<div class="wrap">
<div class="a"><div class="b">Title</div></div>
<div class="c">This is section C.</div>
</div>
Upvotes: 1