I'm facing an issue with banners overlapping images inside a flex-box. When the flex direction is set to row, everything aligns perfectly based on CSS. However, switching to column orientation causes them to stack at the top and cover one another.
<html>
<div class="locations">
<div class="location">
<img src="resources/images/norbert-toth-I1oL89qxefc-unsplash.jpg" />
<div class="location-container>
<h2>Herring Bone Library</h2>
<p>141 Address St. <br>Detroit, MI <br>49449</p>
</div>
</div>
<div class="location ">
<img src="resources/images/kristen-colada-adams-wpCJlKxCNRA-unsplash.jpg" />
<div class="location-container">
<h2>Sunrise Botanical <br>(Downstairs)</h2>
<p>2397 Hatchet Rd. <br>Suite 11 <br>Detroit, MI <br>49447</p>
</div>
</div>
<div class="location">
<img src="resources/images/daria-volkova-_IhXaHmTJr8-unsplash.jpg" />
<div class="location-container">
<h2>Black Cat Coffee</h2>
<p>686 My Mind <br>Detroit, MI <br> 49448</p>
</div>
</div>
</div>
</html>
The location-container banners don't adjust with the flex-box even with additional CSS styling. They overlap only within the main parent container.
Here's how they are styled:
.locations {
display: flex;
justify-content: center;
align-items: center;
margin: 3rem 4rem;
gap: 2rem;
position: relative;
}
.location-container {
position: absolute;
background-color: #fffaf7;
margin-left: 1rem;
padding: 1rem;
top: 1rem;
}
.location-container h2 {
font-family: "Roboto Condensed", sans-serif;
margin-bottom: 1rem;
}
.location-container p {
font-family: "Cabin", sans-serif;
}
.location img {
width: 100%;
max-height: 46rem;
}
@media only screen and (max-width: 1200px) {
.locations {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 3rem 4rem;
gap: 2rem;
position: relative;
}
.location-container {
position: absolute;
background-color: #fffaf7;
margin-left: 1rem;
padding: 1rem;
top: 1rem;
}
}
As the webpage width hits 1200px, the flex-box switches to a column layout while maintaining the positions of text containers.
Any suggestions on keeping the banners aligned properly within flexing parent containers?