I’m trying to make a grid, however I tried to use the width and height on css it doesn’t change a thing.
I’m planning to make this
and this is the thing I tried.
.container {
background-color: #ccc;
margin: 180px;
padding: 100px;
text-align: center;
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
gap: 7px 7px;
grid-template-areas: "A A A A" "B B B F" "C D E F";
justify-content: center;
}
.A {
grid-area: A;
width: 100%;
height: 20%;
}
.B {
grid-area: B;
}
.C {
grid-area: C;
}
.D {
grid-area: D;
}
.E {
grid-area: E;
}
.F {
grid-area: F;
}
<body>
<div class="container">
<div class="A">A</div>
<div class="B">B</div>
<div class="C">C</div>
<div class="D">D</div>
<div class="E">E</div>
<div class="F">F</div>
</div>
</body>
I tried to add the width and height on A class. however it did nothing. I also tried to make the responsive thing but haven’t added the code because I’m too confused about this.
2
Answers
to sets the box-sizing property and adjusts the width and height values of the .A element to fit the grid, please use this:
You need to make the container the full screen height using
height: 100vh
and set the body margin to 0 to make the container fill the full screen. Then use thefr
units in the grid rows and columns to fill the container. There’s no need to set the height or width on the grid children as they’ll only fill that percentage of the space they’ve been allocated in the grid. For a good place to start with grid, check out Kevin Powell’s video here.For the responsive part, I’ve added a media query and just switched from a 4 column 3 row layout to a 3 column 4 row layout. You’ve already used
grid-template-areas
for this which is a great solution for the responsive part. Good luck