I am currently creating a landing page for a website in which I used a flex display for one section. Below this section, I want to create a grid for another section, however the content is being display in between the "flex" content as opposed to below it and I am not sure how to fix it to make the content appear below in another section.
Below is the CSS and HTML of the flex box as well as the grid that I am attempting to add below:
.grid-container2 {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
flex-direction: row;
justify-content: space-around;
padding-bottom: 4rem;
}
.image1,
.image2,
.image3 {
height: 10rem;
margin: 4rem 0 0 0;
}
.image {
width: auto;
height: auto;
}
@media (max-width: 800px) {
.grid-container2 {
flex-direction: column;
}
}
.text {
font-family: Merge;
font-size: large;
}
.link {
font-family: Merge;
font-size: small;
color: black;
}
.grid-container3 {
display: grid;
grid-template-areas: 'col1 col2 col3';
}
<div class="grid-container2">
<div class="image1">
<img class="image" src="images/Customer Landing Page.jpg" alt="Customer - Make a service request">
<div class="text">Make a service request</div>
<a class="link" href="">Sign up as a customer</a>
</div>
<div class="image2">
<img class="image" src="images/Contractor Landing Page 2.jpg" alt="Contractor - Decide on jobs">
<div class="text">Decide what orders you want to fulfill</div>
<a class="link" href="">Decide which job suits you best</a>
</div>
<div class="image3">
<img class="image" src="images/Contractor Landing Page.jpg" alt="Contractor or Business - Create account">
<div class="text">Orders completed by professionals</div>
<a class="link" href="">Sign up as a business or contractor</a>
</div>
</div>
<div class="grid-container3">
<div class="col1">
1
</div>
<div class="col2">
2
</div>
<div class="col3">
3
</div>
</div>
Below is what I am trying to achieve – create a grid below the three pictures where I can add the rounded rectangle and other objects/text.
With the current code, the image is appearing in the flex box segment.
2
Answers
1.) Your problem could be solved by creating a
container
class. You should set this class to useflex
display and position it incolumn
direction as follows:With this class applied to the div, all of your components will be stacked on top of each other. This way, your first component can be a div with three images and also set to use flex display. The second component can be a grid. The third component can be a list. And so on…
2.) Also, you forgot to set your
grid-container2
class to useflex
display and position it inrow
direction by default.3.) And in your
grid-container3
class, you set the default column width to 1, which means that even above 800px viewport width, only one column will be displayed. To fix this, you should adjust the default column width to be greater than 1, or use a media query to modify the number of columns displayed on larger screens.4.) To prevent images from overflowing out of the flex element, you can use
max-width: 100%
styling withheight: auto
.5.) Don’t forget to add the
meta
tag that enables responsiveness from<head>
:Based on your example: