this is the HTML code
body {
background-color: #a7bcb9;
color: #ffffff;
font-family: Parkinsans, sans-serif;
margin: 50px 50px 0px 50px;
display: flex;
flex-direction: column;
min-height: 95vh;
}
.main {
flex: 1;
}
h1 {
font-size: 5rem;
text-align: center;
}
footer {
text-align: right;
color: midnightblue;
}
.tile-image {
float: left;
width: 200px;
margin-right: 5%;
}
.card {
width: 45%
}
.left {
float: left;
}
.right {
float: right;
}
.life {
font-style: italic;
color: #49beb7;
}
@media (max-width: 680px) {
h1 {
font-size: 3.5rem;
text-align: center;
}
.card {
width: 100%;
display: block;
margin-bottom: 30px;
text-align: justify;
}
.card img {
width: 100%;
height: auto;
margin-bottom: 10px;
display: block;
object-fit: cover;
}
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Parkinsans:[email protected]&display=swap" rel="stylesheet">
<div class="main">
<h1>philosophy of <br><span class="life">life</span></h1>
<div class="left card"><img class="tile-image" src="https://placehold.co/600x400" alt="luffy's gear 5ᵗʰ">
<h2 class="card-title">leason of Life</h2>
<p>The things you do in this life is always worth nothing in the end.</p>
</div>
<div class="right card"><img class="tile-image" src="https://placehold.co/600x400" alt="luffy's gear 5ᵗʰ">
<h2 class="card-title">leason of Life 2</h2>
<p>Acumalating wealth is not your job but Acumalating knowlede is.</p>
</div>
</div>
<footer>
<p>Create. Develop. Design.</p>
</footer>
The goal is to stack the image and the paragraph one by one when the max-width:680px this block of code is not working what do you think I went wrong?
2
Answers
This is because you are using float for the images and cards, which doesn’t automatically adapt well to responsive designs.
you should replace the float-based layout with a flexbox or grid layout
You’re using float: left for .left, .right, and .tile-image. Floats can create issues when it comes to layout stacking, especially with media queries.