Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display First DIV beneath Second DIV

Tags:

html

css

say I have...

<div id="A"></div>
<div id="B"></div>

How can the end-user view div B on top of div A on their browser?

I'm trying to do this with CSS without editing the html.

like image 320
Lost305 Avatar asked Jan 23 '26 14:01

Lost305


2 Answers

You can use flex-box and order to acheive what you want

body {
  display: flex;
  flex-wrap:wrap;
}

#A {
  width: 100%;
  height:50px;
  background: red;
  color:white;
  order: 2;
}

#B {
  width: 100%;
  height:50px;
  background: black;
  color:white;
  order: 1;
}
<div id="A">A</div>
<div id="B">B</div>
like image 153
Chiller Avatar answered Jan 26 '26 05:01

Chiller


You need to add display:flex; and flex-direction:column-reverse; to the parent of your two divs.

body{
    display:flex;
    flex-direction:column-reverse;
}

Or you can choose div's order manually with order property:

body {
  display: flex;
}

#A {
  order: 2;
}

#B {
  order: 1;
}
like image 20
Richard Foucaud Avatar answered Jan 26 '26 03:01

Richard Foucaud



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!