I’m having difficulty spanning box-two to take up column two and three. I’ve checked for typos. My page looks great before screen width is 1024px. Below is my html page and stylesheet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="box">
<img src="css/images/blackberries.jpg" alt="blackberries">
</div>
<div class="box box-two">
<img src="css/images/brunch.jpg" alt="brunch">
</div>
<div class="box">
<img src="css/images/utensils.jpg" alt=" cooking utensils">
</div>
<div class="box">
<img src="css/images/blackberries.jpg" alt="blackberries">
</div>
<div class="box">
<img src="css/images/brunch.jpg" alt="brunch">
</div>
<div class="box">
<img src="css/images/utensils.jpg" alt=" cooking utensils">
</div>
<div class="box">
<img src="css/images/blackberries.jpg" alt="blackberries">
</div>
</div>
</body>
</html>
My stylesheet is below. I think the issue lies in my stylesheet but I’m having a hard time pinpointing were.
.container {
display: grid;
grid-template-rows: repeat(auto, 10rem);
grid-template-columns: repeat(1, 10rem);
gap: 10px;
}
img {
width: 10rem;
height: 10rem;
}
@media screen and (min-width:768px) {
.container{
display: grid;
grid-template-columns: repeat(2, 10rem);
}
}
@media screen and (min-width:1024px) {
.container{
display: grid;
grid-template-columns: repeat(3, 10rem);
grid-template-rows: repeat(4, 10rem);
}
.box-two {
grid-column: span 2 ;
}
}
I’ve tried grid-column: 2 / 4 and other variants of the grid-column command but it simply adds additional columns without letting box-two take up multiple columns. My code isn’t bringing up any errors and I’ve tried seeing if I was missing anything elsewhere.
2
Answers
I think your CSS works as-is, but your image doesn’t fill the entire cell when it spans multiple columns so it doesn’t appear to be working.
If you run the snippet below (and open it full-screen to get the layout in question) you can see that
box-two
does span two columns, but your image is stillwidth: 10rem
so it doesn’t grow.This probably isn’t the solution, but just to illustrate: adding this rule will allow the image to scale up and fill the full width:
Try using precise CSS Grid properties (like grid-column-start and grid-column-end) for more control over placement.