Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Responsive page: make the right column stay on top when in one column

Tags:

css

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?

like image 593
curious1 Avatar asked Dec 15 '16 21:12

curious1


1 Answers

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>
like image 117
sol Avatar answered Sep 22 '22 18:09

sol