css - Split available width between two divs -
i have container (width not known) containing 4 divs, follows:
| div1 | div2 ............... | .............. div3 | div4 |
the leftmost , rightmost divs (div1/div4) fixed width; that's easy part.
the width of div2/div3 not known, , avoid setting fixed width them, depending on content 1 can wider other (so cannot e.g. have each 1 use 50% of available space)
i width of div2/div3 automatically computed browser, if there remaining space left, should stretch fill remaining space (it not matter how remaining space split between div2/div3)
the way approaching right is:
- div1 floated left (or absolutely positioned)
- div4 floated right (or absolutely positioned)
- div2 has margin-left equal width of div1 (known)
- div3 has margin-right equal width of div4 (known)
my question is, how have div2 , div3 stretch fill remaining available width? guess 1 option use display: table, , possibility flex-box. there alternatives?
update: edited clarity.
update 2: please note i cannot assume div2 , div3 should each 50% of available space. explicitly stated in question somehow keep getting answers based on assumption.
make use of overflow:hidden
(or overflow:auto - long overflow isn't set visible [the default]) trigger block formatting contexts
fill remaining width
(i have assumed fixed width of 100px div1 , div4)
markup
<div class="div1">div 1</div> <div class="container"> <div class="div2">div 2</div> <div class="div3">div 3</div> </div> <div class="div4">div 4</div>
css
html,body,div { height: 100%; } .div1 { float:left; width: 100px; background: aqua; } .container { overflow: hidden; padding-right: 100px; box-sizing: border-box; background: green; } .div2 { background:yellow; float:left; } .div3 { background:brown; overflow: hidden; } .div4 { position: absolute; right:0; top:0; background:pink; width: 100px; }
Comments
Post a Comment