Solution 1 :

As commented, flex-direction will allow you to reverse the order tath elements are rendered in a row.

main {
  max-width: 1000px;
  height: 100%;
  display: flex;
  flex-direction: row-reverse;
}

.layout-sidebar-first {
  width: 25%;
}

.layout-content {
  width: 75%;
}

As an alternative, you can also use the CSS order property to change the position of a single element without having to reverse the direction of the entire row.

main {
  max-width: 1000px;
  height: 100%;
  display: flex;
}

.layout-sidebar-first {
  width: 25%;
  order: 2;
}

.layout-content {
  width: 75%;
}

Also worth noting that you can use a negative value for order.

.layout-sidebar-first {
  width: 25%;
  order: -1;
}

Problem :

I want main to be as high as the biggest child, but I can’t figure out how to make that work with position: relative&absolute.

HTML

<main>
  <div class="layout-content"></div>
  <aside class="layout-sidebar-first"></aside>
</main>

Because I want to put my aside left and the .layout-content right I have as CSS:

main {
  max-width: 1000px;
  height: 100%;
  position: relative;
}

.layout-sidebar-first {
  width: 25%;
  position: absolute;
  left: 0;
}

.layout-content {
  width: 75%;
  position: absolute;
  right: 0;
}

I’m using Drupal so I can’t put aside before div in the html and use display:flex.

I tried for main CSS:

height:100% or auto;
box-sizing: border-box;
contain: content;
display:block

Comments

Comment posted by Alan Jenkins

I know you say you can’t use display:flex but is that because you can’t change the order your html is rendered? If so, you could try using flex-direction: row-reverse in combination with display: flex.

Comment posted by Ann-Sophie

Alan, you’re totally right! I can use display flex and reverse. I made it work with that. Thanks! Still wondering if there is a solution with position:absolute&relative though 🙂

By