Let's say I want to have two columns. The right one is 200px wide, and the left one just takes up the remaining width. Is this possible? What do I set the width of the left column to be?
Now that we have Flexbox (with over 95% support globally) this layout (and others) can be easily achieved without styles being dependent on source order.
Flexbox Example:
<div class="flex-container"> <div class="flex-column"> Big </div> <div class="fixed-column"> Small </div> </div>
.flex-container { display: flex; } .flex-column { flex: 1; } .fixed-column { width: 200px; }
The trick is matching the remainder column’s margin to the floated sidebar’s width. Remember, source order matters when using floats, so we make sure the floated element comes first.
Example right-aligned small column:
<div id="Container"> <div id="RightColumn">Right column</div> <div id="LeftColumn">Left column</div> </div>
#RightColumn { float : right; width : 200px; } #LeftColumn { margin-right : 200px; }
You float
the left column and set margin to minimum of the width of the left column.
<div id="Container"> <div id="LeftColumn" style="float: left; margin-right: 200px;"></div> <div id="RightColumn" style="float: right; width: 200px;"></div> </div>
OR
<div id="Container"> <div id="RightColumn" style="float: right; width: 200px;"></div> <div id="LeftColumn" style="margin-right: 200px;"></div> </div>
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