I have 3 divs in 3 columns of a grid and I want the middle div to stay static when zoomed in. The one on the right and left growing with the zoom
HTML
<mdiv class="dvCenter">
<div class="dvCenter1"></div>
<div class="dvCenter2"></div>
<div class="dvCenter3"></div>
</div>
CSS
.dvCenter{
background-color: black;
height: 110px;
align-items: center;
display: grid;
grid-template-columns: 40% 20% 40%;
grid-template-rows: 100%;
}
.dvCenter1{
background-color: blue;
height: 80%;
grid-row: 1;
grid-column: 1;
}
.dvCenter2{
background-color: brown;
height: 100%;
grid-row: 1;
grid-column: 2;
}
.dvCenter3{
background-color: blue;
height: 80%;
grid-row: 1;
grid-column: 3;
}
I think what you want is to have the page start by having the .dvCenter2 div to have 20% width and then stays as the current width when the page grows. But % is a relative unit and when the screen grows bigger, the 20% is also bigger than the original 20%.
I can't think of a pure CSS way to do this but you can use javascript to query the current size of the container and modify the grid-template-column. Check the demo below. Hope this helps!
$(".dvCenter").css("grid-template-columns", "1fr " + $(".dvCenter2").width() + "px 1fr");
$("#btn").click(function() {
$(".dvCenter").toggleClass("enlarge");
});
.dvCenter{
background-color: black;
height: 110px;
width: 50%;
align-items: center;
display: grid;
grid-template-columns: 1fr 20% 1fr;
grid-template-rows: 100%;
}
.dvCenter1{
background-color: blue;
height: 80%;
grid-row: 1;
grid-column: 1;
}
.dvCenter2{
background-color: brown;
height: 100%;
grid-row: 1;
grid-column: 2;
}
.dvCenter3{
background-color: blue;
height: 80%;
grid-row: 1;
grid-column: 3;
}
.enlarge {
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<mdiv class="dvCenter">
<div class="dvCenter1"></div>
<div class="dvCenter2"></div>
<div class="dvCenter3"></div>
</div>
<button id="btn">Click to resize container</button>
Related
I need to achieve a grid item to be wider than the grid frame.
However, it seems that this is not possible with a standard way.
Any idea?
.grid {
display: grid;
grid-template-columns: 200px 200px 200px;
}
.grid-item {
position: absolute;
width: 300px;
}
As you put it, the item is already wider that its grid box. There is no need to add position absolute. For better understanding of what is going on, while working on grid, it is recomended to use firefox since it help you visualize every grid line.
.grid {
display: grid;
background-color: red;
grid-template-columns: 200px 200px 200px;
}
.grid-item1 {
background-color: blue;
width: 300px;
height: 300px;
}
.grid-item2 {
background-color: green;
width: 300px;
height: 300px;
}
.grid-item3 {
background-color: yellow;
width: 300px;
height: 300px;
}
<div class="grid">
<div class="grid-item1"></div>
<div class="grid-item2"></div>
<div class="grid-item3"></div>
</div>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
}
.container {
width: 50vw;
height: 50vh;
border: 1px solid red;
}
.grid {
width: 70vw;
height: 70vh;
margin: -10vh -10vw -10vh -10vw;
position: relative;
display: grid;
grid-template-columns: repeat(7, 10vw);
grid-template-rows: repeat(7, 10vh);
}
.c {
grid-column: 4 / -4;
grid-row: 4 / -4;
}
.n {
grid-column: 4 / -4;
grid-row: 1 / 2;
}
.s {
grid-column: 4 / -4;
grid-row: -2 / -1;
}
.e {
grid-column: -2 / -1;
grid-row: 4 / -4;
}
.w {
grid-column: 1 / 2;
grid-row: 4 / -4;
}
.ne {
grid-column: -2 / -1;
grid-row: 1 / 2;
}
.se {
grid-column: -2 / -1;
grid-row: -2 / -1;
}
.nw {
grid-column: 1 / 2;
grid-row: 1 / 2;
}
.sw {
grid-column: 1 / 2;
grid-row: -2 / -1;
}
.c,
.n,
.s,
.e,
.w,
.ne,
.nw,
.se,
.sw {
border: 1px solid #000;
}
<div class="container">
<div class="grid">
<div class="c"></div>
<div class="n"></div>
<div class="ne"></div>
<div class="e"></div>
<div class="se"></div>
<div class="s"></div>
<div class="sw"></div>
<div class="w"></div>
<div class="nw"></div>
</div>
</div>
I'm trying to build a grid where the first-row would have 400px and the second would be something like fit-content, since my first column is dynamically created and it can have an undertemined height.
The idea is, I have three blocks, 1 is dynamic, 2 and 3 are static, where 3 should always be below 2:
However I couldn't find a way to make the first row with a fixed value (400px) and the second auto to fit whatever height the block 1 have. If I set the first one auto and the second row 400px I get this:
.container {
display: grid;
grid-template-columns: auto auto;
grid-template-rows: auto 400px;
width: 400px;
}
.block-1 {
height: 300px;
width: 200px;
background: red;
}
.block-2 {
height: 100px;
width: 150px;
background: blue;
grid-column: 3/5;
}
.block-3 {
height: 100px;
width: 150px;
background: green;
grid-column: 3/5;
grid-row-start: 2;
}
<div class="container">
<div class="block-1"></div>
<div class="block-2"></div>
<div class="block-3"></div>
</div>
Is there a way to do that with grid? I could change the structure of the grid, the way I bult is not a must.
P.S. Changing the HTML is not an option.
Is this what you want?
.container {
display: grid;
grid-template-columns: auto auto;
grid-template-rows: auto 400px;
width: 400px;
}
.block-1 {
height: 300px;
width: 200px;
background: red;
grid-row: 1 / 3;
}
.block-2 {
height: 100px;
width: 150px;
background: blue;
}
.block-3 {
height: 100px;
width: 150px;
background: green;
grid-column: 2/3;
grid-row-start: 2;
}
<div class="container">
<div class="block-1"></div>
<div class="block-2"></div>
<div class="block-3"></div>
</div>
This seems like it will do the trick. I've used named grid-template-areas as shorthand.
.container {
display: grid;
grid-auto-columns: 1fr;
grid-auto-rows: 1fr;
grid-template-columns: 1fr 1fr;
grid-template-rows: min-content;
gap: 0px 0px;
grid-template-areas:
"block-1 block-2"
"block-1 block-3";
width: 400px;
}
.block-1 { grid-area: block-1; background-color: red; height: 300px}
.block-2 { grid-area: block-2; background-color: blue; height: 100px }
.block-3 { grid-area: block-3; background-color: green; height: 100px; }
<div class="container">
<div class="block-1"></div>
<div class="block-2"></div>
<div class="block-3"></div>
</div>
Hopefully that works out for you, but if you need to make any adjustments then I always find using a site with a visual UI for the grid really helps, e.g. https://grid.layoutit.com/
I'm trying to sort out a css grid to fit my imgs on this tribute page project from free code camp. I managed to do the grid as I wanted to but I can't seem to fit the images perfectly in each cell. Some of them are not filling the entire cell and others are exceeding it. This is the code:
.img-div-container {
display: grid;
grid-template-columns: 50% 25% 25%;
grid template-rows: 5px 5px;
margin-left: 100px;
margin-right: 100px;
grid-column-gap: 5px;
align-content: stretch;
justify-content: stretch;
background: hsla(199, 19%, 62%, 0.21);
border: 2px outset hsla(199, 19%, 62%, 0.21)
}
.image-bigger {
grid-column: 1/2;
grid-row: 1/3;
place-self: stretch;
;
}
.image-wider {
grid-column: 2/4;
grid-row: 2/3;
place-self: end stretch;
width: 95%;
}
.image-normal,
.image-bigger,
{
place-self: stretch;
justify-self: flex-start;
}
img {
width: 100%;
height: 87%;
}
.normal {
width: 100%;
height: auto;
}
<div class="img-div-container">
<div class="image-bigger"><img src="http://s2.glbimg.com/eP3_5jDhj_6tF-nyyiGpPOKdHNh8tT68kXTqIHZg3lBrXaqmUDsPSdlfxwreNWMq/e.glbimg.com/og/ed/f/original/2012/10/29/754_carlos_marighella.jpg"></div>
<div class="image-normal"><img class="resize" src="https://drupal-multisite-s3.s3-us-west-2.amazonaws.com/files/marighella2.jpg"></div>
<div class="image-normal"><img class="normal" src="http://www.cartografiasdaditadura.org.br/files/2014/12/Carlos_Marighella.jpg"></div>
<div class="image-wider"><img class="normal" id="bigode" src="http://memoriasdaditadura.org.br/wp-content/uploads/2014/11/mariguella4-e1471390559677-600x286.jpg"></div>
</div>
I'm sorry the code got a little bit messy when trying to fix this.
The biggest change I did is to add the property object-fit to your images:
img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
https://www.w3schools.com/css/css3_object-fit.asp
For the rest, I have only commented on some of your rules that I considered unnecessary to this work:
.img-div-container {
display: grid;
grid-template-columns: 50% 25% 25%;
/*grid-template-rows: 5px 5px;*/
margin-left: 100px;
margin-right: 100px;
grid-gap: 5px;
/*align-content: stretch;
justify-content: stretch;*/
background: hsla(199, 19%, 62%, 0.21);
border: 2px outset hsla(199, 19%, 62%, 0.21);
overflow:hidden;
}
.image-bigger {
grid-column: 1/2;
grid-row: 1/3;
/*place-self: stretch;*/
}
.image-wider {
grid-column: 2/4;
grid-row: 2/3;
/*place-self: end stretch;
width: 95%;*/
}
/*.image-normal,
.image-bigger,
{
place-self: stretch;
justify-self: flex-start;
}*/
img {
width: 100%;
height: 100%;
display:block;
object-fit: cover;
}
/*.normal {
width: 100%;
height: auto;
}*/
<div class="img-div-container">
<div class="image-bigger"><img src="http://s2.glbimg.com/eP3_5jDhj_6tF-nyyiGpPOKdHNh8tT68kXTqIHZg3lBrXaqmUDsPSdlfxwreNWMq/e.glbimg.com/og/ed/f/original/2012/10/29/754_carlos_marighella.jpg"></div>
<div class="image-normal"><img class="resize" src="https://drupal-multisite-s3.s3-us-west-2.amazonaws.com/files/marighella2.jpg"></div>
<div class="image-normal"><img class="normal" src="http://www.cartografiasdaditadura.org.br/files/2014/12/Carlos_Marighella.jpg"></div>
<div class="image-wider"><img class="normal" id="bigode" src="http://memoriasdaditadura.org.br/wp-content/uploads/2014/11/mariguella4-e1471390559677-600x286.jpg"></div>
</div>
Try to give your grid grid-template-areas
and then grid-area to each div accordingly,
for example:
HTML
<div class="grid-container">
<div class="verticalphoto"></div>
<div class="photo1"></div>
<div class="photo2"></div>
</div>
CSS
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-areas:
"verticalphoto photo1 . ." "verticalphoto photo2 . ." ". . . .";
}
.verticalphoto { grid-area: verticalphoto; }
.photo1 { grid-area: photo1; }
.photo2 { grid-area: photo2; }
to fit the image, try,
img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
you are using
display: grid;
grid-template-columns: 50% 25% 25%;
grid template-rows: 5px 5px;
which seems coherent 3 colums and 2 rows.
I would use
display:grid;
grid-template-columns: 50% 25% 25%;
grid-template-rows:1fr 1fr;
to avoid a fixed value and let the browser manage sizing for the rows.
Then , you use
.image-wider {
grid-column: 2/4;
grid-row: 2/3;
}
Which would work perfectly with a grid-template-areas if areas described 4 columns and 3 rows, which is obviously not the case here (you setted 3 columns and 2 rows ) .
I would safely use here for a grid-template-columns / grid-template-rows :
.image-wider {
grid-column: 2 / span 2; /* set in the second column and span through 2 columns */
grid-row: 2;/* not really needed here since it is already standing in the last empty grid cell avalaible */
}
tell only how many cell there is to span through instead telling go from cell 2 to cell 4 (grid-template-areas was not set ! )
When using flex or grid, if you are unfamiliar with it, make it into steps as simple as possible .
You could have start to build your grid layout with a few extra class to make it easier to read at first and easier to tune later.
the row-gap also seems to me more alike a margin-bottom for the first 2 small grid.
code example broken into pieces to show where to dispatch each containers ;)
.grid {
display:grid;
margin:0 100px;
grid-template-columns: 50% 25% 25%;
grid-template-rows:1fr 1fr;
}
.c1 {
grid-column:1;
}
.c2 {
grid-column:2;a
}
.c3 {
grid-column:3;
}
.c23 {
grid-column:2/ span 3;
}
.r1 {
grid-row:1;
}
.r2 {
grid-row:2;
}
.r12 {
grid-row:1/ span2;
}
.image-normal {
margin-bottom:5px;
}
/* whatever size is needed , object-fit can also be used to clip and avoid pixel stretching */
img {
height:100%;
width:100%;
}
<div class="img-div-container grid">
<div class="image-bigger c1 r12">
<img src="http://s2.glbimg.com/eP3_5jDhj_6tF-nyyiGpPOKdHNh8tT68kXTqIHZg3lBrXaqmUDsPSdlfxwreNWMq/e.glbimg.com/og/ed/f/original/2012/10/29/754_carlos_marighella.jpg">
</div>
<div class="image-normal c2 r1">
<img class="resize" src="https://drupal-multisite-s3.s3-us-west-2.amazonaws.com/files/marighella2.jpg">
</div>
<div class="image-normal c3 r1">
<img class="normal" src="http://www.cartografiasdaditadura.org.br/files/2014/12/Carlos_Marighella.jpg">
</div>
<div class="image-wider c23 r2">
<img class="normal" id="bigode" src="http://memoriasdaditadura.org.br/wp-content/uploads/2014/11/mariguella4-e1471390559677-600x286.jpg">
</div>
</div>
Looks like you mixed grid-template-areas and grid-template-rows (-columns) to fill your grid .
I am trying to create three items inside of a nested grid item. As you can see from the code, I've put the 'panels' div in-between the 'jumbo' and 'content' divs. I also nested three divs inside. In the CSS, I added a nested grid inside of .panels.
I want the 'panels' div to be split in three equally size parts on the vertical axis. Imagine three square blocks stack one after another. But the nested items don't fill the entire 'panels' div. If you run the code snippet, you can see that the panels are nested but don't take up the entire space. They take up a small percentage of their parent. I added background-color: white !important to one of the nested panels to show how small it is.
Another example can be seen here: https://codepen.io/rachelandrew/pen/NqQPBR/
But again, the nested E, F and G items don't expand to fill up the entire D section.
Is there a way to make the three panels fill in their parent?
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
align-items: center;
font-size: 2em;
color: #ffeead;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) {
background-color: #96ceb4;
}
.container > div:nth-child(3n) {
background-color: #88d8b0;
}
.container > div:nth-child(2n) {
background-color: #ff6f69;
}
.container > div:nth-child(4n) {
background-color: #ffcc5c;
}
.panels > div:nth-child(1n) {
background-color: #96ceb4;
}
<div class="container">
<div class="header">
HEADER
</div>
<div class="jumbo">
JUMBO
</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">
CONTENT
</div>
<div class="footer">
FOOTER
</div>
</div>
You have align-items: center applied to the nested grid container (.panels).
With that rule, you override the default align-items: stretch, which would set your grid items to the full height of the parent. Instead, you have the items vertically centered.
So they can be full height, remove align-items: center from the .panels element:
.container > div:not(.panels) {
align-items: center;
}
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
/* align-items: center; */
font-size: 2em;
color: #ffeead;
}
/* new */
.container > div:not(.panels) {
align-items: center;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) { background-color: #96ceb4; }
.container > div:nth-child(3n) { background-color: #88d8b0; }
.container > div:nth-child(2n) { background-color: #ff6f69; }
.container > div:nth-child(4n) { background-color: #ffcc5c; }
.panels > div:nth-child(1n) { background-color: #96ceb4; }
<div class="container">
<div class="header">HEADER</div>
<div class="jumbo">JUMBO</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">CONTENT</div>
<div class="footer">FOOTER</div>
</div>
Then, to vertically center the content of .panels, I would target the content directly:
.panels > div {
display: flex;
align-items: center;
}
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(10, 1fr);
grid-template-rows: 40px 130px 130px 130px 60px 330px 40px;
}
.header {
grid-column: 1 / -1;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panels {
grid-column: 3 / 9;
grid-row: 4 / 6;
z-index: 1;
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.panel1 {
grid-row: 1 / 2;
grid-row: 1;
background-color: white !important;
z-index: 2;
}
.content {
grid-column: 1 / -1;
grid-row: 5 / 7;
}
.footer {
grid-column: 1 / -1;
}
/* Styling */
.container > div {
display: grid;
justify-content: center;
/* align-items: center; */
font-size: 2em;
color: #ffeead;
}
/* new */
.container > div:not(.panels) {
align-items: center;
}
/* new */
.panels > div {
display: flex;
align-items: center;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) { background-color: #96ceb4; }
.container > div:nth-child(3n) { background-color: #88d8b0; }
.container > div:nth-child(2n) { background-color: #ff6f69; }
.container > div:nth-child(4n) { background-color: #ffcc5c; }
.panels > div:nth-child(1n) { background-color: #96ceb4; }
<div class="container">
<div class="header">HEADER</div>
<div class="jumbo">JUMBO</div>
<div class="panels">
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
</div>
<div class="content">CONTENT</div>
<div class="footer">FOOTER</div>
</div>
Keep in mind that there are three structural levels in a grid container:
the container
the item (child of the container)
the content (child of the item)
Grid properties only work between parent and child.
So when you apply grid centering properties on the container, they apply to the item, not the content. To center the content, you need to treat the item as parent and content as child.
There's a more in-depth explanation of these concepts and methods here: Centering in CSS Grid
Well, what you have done is, you created three columns inside the 'panels' div:
grid-template-columns: repeat(3, 1fr);
But you gave the children only a position for the row (twice):
grid-row: 1 / 2;
grid-row: 1;
So if you change 'columns' to 'rows' in '.panels' and clean up the code for '.panel1' it should work like a cham!
Thank you all for your suggestions. I solved the issue by removing the nested 'panel' and simply creating three different panels to fill the same space.
.container {
display: grid;
width: 100%;
height: 100%;
grid-gap: 3px;
grid-template-columns: repeat(13, 1fr);
grid-template-rows: 50px 218px 218px 200px 80px 530px 40px;
}
.header {
grid-column: 1 / -1;
position: sticky;
top: 0;
z-index: 3;
}
.jumbo {
grid-column: 1 / -1;
grid-row: 2 / 5;
}
.panel1 {
background-color: white !important;
z-index: 1;
grid-column: 3 / 6;
grid-row: 4 / 6;
}
.panel2 {
background-color: black !important;
z-index: 1;
grid-column: 6 / 9;
grid-row: 4 / 6;
}
.panel3 {
background-color: purple !important;
z-index: 2;
grid-column: 9 / 12;
grid-row: 4 / 6;
}
.content-left {
grid-column: 1 / 5;
grid-row: 5 / 7;
}
.content-right {
grid-column: 5 / -1;
grid-row: 5 / 7;
display: grid;
grid-gap: 5px;
align-items: start;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr)
}
.content-right > div {
background-color: white;
z-index: 2;
}
.footer {
grid-column: 1 / -1;
}
.container > div {
justify-content: center;
align-items: center;
font-size: 2em;
color: #ffeead;
}
html, body {
background-color: #ffeead;
box-sizing: border-box;
height: 100%;
margin: 0px;
font-family: "Work Sans"
}
.container > div:nth-child(1n) {
background-color: #96ceb4;
}
.container > div:nth-child(3n) {
background-color: #88d8b0;
}
.container > div:nth-child(2n) {
background-color: #ff6f69;
}
.container > div:nth-child(4n) {
background-color: #ffcc5c;
}
.panels > div:nth-child(1n) {
background-color: #96ceb4;
}
<div class="container">
<div class="header">
HEADER
</div>
<div class="jumbo">
JUMBO
</div>
<div class="panel1">PANEL1</div>
<div class="panel2">PANEL2</div>
<div class="panel3">PANEL3</div>
<div class="content-left">
CONTENT-LEFT
</div>
<div class="content-right">
<div class="content-right1">1</div>
<div class="content-right2">2</div>
<div class="content-right3">3</div>
<div class="content-right4">4</div>
<div class="content-right5">5</div>
<div class="content-right6">6</div>
</div>
<div class="footer">
FOOTER
</div>
</div>
How can I prevent the footer row from overlapping the content row?
This is what I'm getting:
body {
display: grid;
grid-template-rows: 3.7rem auto auto;
grid-template-columns: 3rem 3fr 2fr;
}
*[role="banner"] {
grid-row: 1;
grid-column: 2/4;
background-color: green;
height: 3rem;
}
*[role="main"] {
grid-row: 2;
grid-column: 2;
background-color: yellow;
height: 100px;
}
*[role="contentinfo"] {
grid-row: 3;
grid-column: 2/3;
border-top: 1px solid black;
}
*[role="contentinfo"] img {
height: 100px;
}
<div role="banner"></div>
<article role="main"><p>Some Text.</p><p>Some more text</p><p>the last text</p></article>
<footer role="contentinfo"><img src="https://s14-eu5.ixquick.com/cgi-bin/serveimage?url=https%3A%2F%2Fdata.motor-talk.de%2Fdata%2Fgalleries%2F0%2F147%2F9424%2F43109894%2Fbild--7008737403287221413.jpg&sp=6a4eaf3bd8ff58ca9d9bba2e3519888e"></footer>
The footer (row 3) is overlapping the article (row 2) because you have a fixed height on the article:
[role="main"] { height: 100px; }
The overrides the auto height you have specified on the grid container with:
grid-template-rows: 3.7rem auto auto
Once you remove the height rule, the overlap is gone.
body {
display: grid;
grid-template-rows: 3.7rem auto auto;
grid-template-columns: 3rem 3fr 2fr;
}
*[role="banner"] {
grid-row: 1;
grid-column: 2/4;
background-color: green;
height: 3rem;
}
*[role="main"] {
grid-row: 2;
grid-column: 2;
background-color: yellow;
/* height: 100px; <-------- REMOVE */
}
*[role="contentinfo"] {
grid-row: 3;
grid-column: 2/3;
border-top: 1px solid black;
}
*[role="contentinfo"] img {
height: 100px;
}
<div role="banner"></div>
<article role="main"><p>Some Text.</p><p>Some more text</p><p>the last text</p></article>
<footer role="contentinfo"><img src="https://s14-eu5.ixquick.com/cgi-bin/serveimage?url=https%3A%2F%2Fdata.motor-talk.de%2Fdata%2Fgalleries%2F0%2F147%2F9424%2F43109894%2Fbild--7008737403287221413.jpg&sp=6a4eaf3bd8ff58ca9d9bba2e3519888e"></footer>