Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS, how to I change the vertical order of div blocks?

I've got a header/logo with div blocks on the right and left:

  .wrap .title-area {
    position: absolute;
    top: 0;
    width: 100%
  }
<div class="wrap">
  <div class="header-left-box">
    <p>abcd-left box</p>
  </div>
  <div class="title-area">
    <p>abcd-header</p>
  </div>
  <div class="header-right-box">
    <p>abcd right box</p>
  </div>
</div>

I styled it with 30%, 40%, 30% width and each has float:left to give the results I need. On reduced screen size, I give each div box 100% width so they stack. But because I want the logo box at the top, I give the style.

That brings the header to the top but the header-left-box also stays at the top, under the header. How can I arrange those as needed without them overlapping?

like image 206
Jim Smith Avatar asked Mar 24 '16 18:03

Jim Smith


People also ask

How can I reorder my divs using only CSS?

We can reorder HTML elements by using many methods in CSS. We use flexbox's order property. Order property is used to change the visual order and not their logical order. Items in a container are sorted in ascending order value and then by their source code order.

How do you reverse the order of elements in CSS?

row-reverse displays the elements in reverse order horizontally, while column-reverse displays the elements in reverse order vertically.


1 Answers

You can achieve this with flex. For the reduced screen size you can use this aditionally

.title-area {
    order: -1 //Move the title area above the others
}

.wrap {
    display:flex;
    flex-direction: column;
}
like image 89
Maak Avatar answered Oct 15 '22 18:10

Maak