I have the following html:
<div class="left">
this is left side. it should go to the bottom when in one column
</div>
<div class="right">
this is right side. it should go to the top when in one column
</div>
css:
.left {
width: 70%;
float: left;
background-color: red;
}
.right {
width: 30%;
float: left;
background-color: yellow;
}
@media only screen and (max-width : 768px) {
.left, .right {
width: 100%;
}
}
I am hoping to make the right column stay on top when the display is one column.
Here is the jsfiddle link: https://jsfiddle.net/m7zpoc30/1/
What should I do, including changes to my current CSS?
Here's a solution using flex, which might be of interest. You can wrap your left and right divs in a container with display:flex
, and then use flex-direction on resize. See snippet below. (jsfiddle)
.container {
display: flex;
}
.left {
width: 70%;
background-color: red;
}
.right {
width: 30%;
background-color: yellow;
}
@media only screen and (max-width: 768px) {
.container {
flex-direction: column-reverse;
}
.left, .right {
width: 100%;
}
}
<div class="container">
<div class="left">
this is left side. it should go to the bottom when in one column
</div>
<div class="right">
this is right side. it should go to the top when in one column
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With