I'm going crazy trying to get the following layout right:
- left div with fixed width (possibly multiple divs one beside another)
- center div with auto width (takes up remaining space)
- right div with fixed width (possibly multiple divs one beside another)
- a margin should exist between center div and first neighbor, be it left or right
HTML
<div class="container">
<div class="all left">
Left1
</div>
<div class="all left">
Left2
</div>
<div class="all center">
Center
</div>
<div class="all right">
Right1
</div>
<div class="all right">
Right2
</div>
</div>
CSS
.container {
display: table;
position: relative;
width: 100%;
height: 100px;
border-spacing: 5px;
}
.all {
display: table-cell;
border: 1px solid #333;
margin: 5px;
}
.left {
width: 45px;
}
.right {
width: 45px;
}
.center {
width: auto;
}
FIDDLE
http://jsfiddle.net/ozrentk/VdryG/3/
However, whatever I try (e.g. putting border-spacing: 0px
in left or right div, margin: 0
, border-collapsing) all of my margins end up the same.
To simplify it, I want this:
+--------------------------------------------------------------+
|+-----++-----+ +------------------------------++-----++-----+|
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|| || | | || || ||
|+-----++-----+ +------------------------------++-----++-----+|
+--------------------------------------------------------------+
But currently I have this:
+--------------------------------------------------------------+
| |
| +----+ +----+ +--------------------------+ +----+ +----+ |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| +----+ +----+ +--------------------------+ +----+ +----+ |
| |
+--------------------------------------------------------------+
How can I control individual margins in this layout?
P.S.
- I don't want the solution with mixing floats with non-floats, because it ends up with layout issues, see this
- I don't want the solution with css calc because it is experimental
- I don't want JS solution because I believe that CSS should be used for this kind of layout and can lead to flickers; also, user can have JS disabled