Creating an overlay in CSS-Grid

I am trying to create an overlay in a CSS3 grid, but I cannot figure out how I can do this. I searched the Internet but didn’t find anything. I want to achieve something like below:

enter image description here

body {
  margin: 0;
  padding: 0;
}

.wrapper {
		display: grid;
		grid-template-rows: 1f;
    width: 100vw;
    height: 100vh; 
    grid-template-areas:
      "a"
      "b"
      "c";
	}

.box {
  background-color: #444;
  color: #fff;
}

.a {
  grid-area: a;
}

.b {
  grid-area: b;
}

.c {
  grid-area: c;
}
<div class="wrapper">
  <div class="box a">A</div>
  <div class="box b">B</div>
  <div class="box c">C</div>
</div>
Run code

Here is the link to codepen: https://codepen.io/anon/pen/PROVeY

+4
source share
1 answer

Like this:

The areas of grid templates are not the most useful here. It is better to define the column / rows independently, and then assign them elements individually. Then align them as needed.

body {
    margin: 0;
    padding: 0;
}

.wrapper {
  margin:auto;
  width:90vw;
    display: grid;
    height: 100vh; 
  grid-template-columns:1fr; /* only one column */
  grid-template-rows:1fr auto; /* 2 rows */
    }
.a,
.b {
  grid-column:1; /* first-column */
  grid-row:1; /* first row */
}



.b {
  width:3em;
  height:3em;
  align-self: end; /* bottom of column */
  justify-self: end; /* right of row */
  margin:1em;
}

.box {
  border:1px solid green;
}
<div class="wrapper">
  <div class="box a">A</div>
  <div class="box b">B</div>
  <div class="box c">C</div>
</div>
Run code
+2
source

Source: https://habr.com/ru/post/1695423/


All Articles