To achieve your desired look, you have two options: utilizing the flexbox
method or employing a grid
system. While there are other methods available, these are the main choices we have.
My recommendation is to use a grid system instead of flex if you aim for a dynamic layout.
- Option one (using
flexbox
)
.one, .two, .three {
height: 50px;
width: 100px;
margin: 20px;
background-color: blue;
}
.main {
display: flex;
}
@media only screen and (max-width: 368px) {
.main {
display: block;
}
.two {
position: absolute;
left:130px;
top:2px;
height: 120px;
background-color: red;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Option 1</title>
</head>
<body>
<div class="main">
<div class="one">Left</div>
<div class="two">Center</div>
<div class="three">Right</div>
</div>
</body>
</html>
- Option two (Recommended) using
grid
system
.grid-container {
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
}
.grid-item {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 20px;
font-size: 30px;
}
.item1 {
grid-column: 1;
grid-row: 1;
}
.item2 {
grid-column: 2;
grid-row: 1;
}
.item3 {
grid-column: 3;
grid-row: 1;
}
@media only screen and (max-width: 368px) {
.item1 {
grid-column: 1 / span 2;
grid-row: 1;
}
.item2 {
grid-column: 3;
grid-row: 1 / span 2;
}
.item3 {
grid-column: 1 / 3;
grid-row: 2;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="grid-container">
<div class="grid-item item1">Left</div>
<div class="grid-item item2">Center</div>
<div class="grid-item item3">Right</div>
</div>
</body>
</html>
I hope this guidance helps you in reaching your design objectives. Enjoy implementing it!