I am trying to make something like this:
|--------------------------------------------------------|-------------|
| | |
| DIV 1 | |
| | DIV 3 |
|--------------------------------------------------------| |
| DIV 2 | |
|--------------------------------------------------------|-------------|
I can't use a table for this. And I don't know if there's a way to just let them stack like that?
I tried it with the code below, but DIV 3 is not all the way at the top. It is actually exactly div2.height lower from the top.
#DIV_1 {
height: 125px;
width: 80%;
display: block;
float: left;
}
#DIV_2 {
width: 80%;
height: 15px;
display: block;
}
#DIV_3 {
display: block;
float: left;
height: 140px;
width: 20%;
}
<div class="row" style="width: 1024px; height: 140px;">
<div>
<div id="DIV_1"></div>
<div id="DIV_2"></div>
</div>
<div id="DIV_3">
</div>
</div>
Three or more different div can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
Start by adding an element with a class of row. This will create a horizontal block to contain vertical columns. Then add divs with a column class within that row. Specify the widths of each column with the small-#, medium-#, and large-# classes.
Three or more different div can be put side-by-side using CSS in the same div. This can be achieved with flexbox – but note that you will need to use wrapper divs and apply different flex-directions to each in order to make the grid layout work.
The layout is relatively simple with CSS flexbox:
.row {
display: flex; /* establish flex container */
height: 140px; /* height from original code */
width: 1024px; /* width from original code */
}
.row > div:first-child {
flex: 0 0 80%; /* width from original code */
display: flex;
flex-direction: column; /* stack first div children vertically */
}
.row > div:first-child > div {
flex: 1; /* items in first div distribute space equally */
border: 1px dashed black;
}
.row > div:last-child {
flex: 0 0 20%;
border: 1px dashed black;
}
<div class="row">
<div>
<div id="DIV_1">DIV #1</div>
<div id="DIV_2">DIV #2</div>
</div>
<div id="DIV_3">DIV #3</div>
</div>
Benefits of flexbox:
Browser support:
Flexbox is supported by all major browsers, except IE < 10. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add prefixes use Autoprefixer. More details in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With