How can I modify the css below such that Box 3 is right below Box 1?
Without modifying any of the html or at least semantically box-1, box-2, box-3, box-4 has to be in this specific order with that layout.
All elements have flexible height.
https://jsfiddle.net/kuyfjho7/
#parent {
width: 1100px;
}
#box-1 {
background: green;
height: 100px;
width: 200px;
float: right;
}
#box-2 {
background: red;
height: 200px;
width: 800px;
}
#box-3 {
background: yellow;
height: 150px;
width: 200px;
float: right;
}
#box-4 {
background: gray;
height: 1000px;
width: 800px;
}
<div id="parent">
<div id="box-1">Box 1</div>
<div id="box-2">Box 2</div>
<div id="box-3">Box 3</div>
<div id="box-4">Box 4</div>
</div>
Layout needed:
2
Answers
Using flexbox and specifying the
order
for each box might work. This may not work as you want with variable height content though since these are all in the same "row" it will change the height of it’s sibling as well.In my experience, You could set display:flex CSS property to the parent div tag and set order as you wish to the child divs such as "order: 4".
And Set the "align-items:start || end || …" to the child divs so that they can have their correct width and height. Hope this could help you.