I need a layout with three drawers (two optional):
[side box 1] [main content
[side box 2]. main content]
or
[main content covers 100% if side windows are not provided]
I want the main content box to cover the entire height and width available in #load (minus margins), except when the side windows are there, then I want it to cover only those fields (and their right margin).
My CSS:
#load { margin: 10px; height: 100%; min-width: 1080px; } #primary,#secondaryOne,#secondaryTwo { border-radius: 8px; background: #f5f5f5; border: 1px solid #ccc; } #primary { float: right; height: inherit; width: 75%; height:500px; background:red; } #secondaryOne,#secondaryTwo { min-width: 250px; max-width: 300px; height: 220px; margin-right: 10px; width: 20%; clear:left; float:left; } #secondaryTwo { margin-top: 10px; }
Plain html
<div id='load'> <div id='primary'></div> <div id='secondaryOne'></div> <div id='secondaryTwo'></div> </div>
Jsfiddle
Problems
* SOLVED * Apply #primary width to full width if side panels are missing.
* SOLVED * Is there a way to link the two side boxes (# secondaryOne, # secondaryTwo) on the left side of #primary without inserting them in a separate div? If I use float: left on them, they are built next to each other, if I do not swim, #primary is generated under them, and not next to them.
Decision
- Problem # 1 was resolved by joeytje50 using secondary + primary tags and placing secondary side boxes in front of the primary in HTML.
- Problem number 2 was resolved in more than one way. The way I chose so that the secondary tags were placed together, and before the primary - NoobEditor, using
clear: left and a negative margin-top .
The solution can be found at: http://jsfiddle.net/v4cvv/67/
The main part of the solution:
#primary { width: 100%; } #secondaryOne + #primary, #secondaryTwo + #primary { margin-top: -221px; width: 75%; }
Alternative solution
One problem that I found using the above solution requires that the two drawers and they be the same height. The solution around this is to group the boxes in their own div. This solution:
HTML
<div id='load'> <div id="sideboxes"> <div id="boxOne" class="box"></div> <div id="boxTwo" class="box"></div> <div id="boxThree" class="box"></div> </div> <div id="primary" class="box"></div> </div>
CSS
.box { border-radius: 8px; background: #f5f5f5; border: 1px solid #fff; } #primary { float: right; display:block; height: 97%; width: 100%; } #sideboxes + #primary { width: 75%; } #sideboxes { float: left; height: 97%; width: 23%; margin-right: 10px; } #sideboxes .box { float: left; height: 220px; margin-bottom: 10px; width: 100%; }
An alternative solution no longer requires a clear and can be expanded for other purposes. Now you can also have 1, 2, 3 or any number of boxes in the side boxes.
Thank you all for your help.