How To Create A 3 Columns Fluid Fixed Fluid Layout?
I'm looking for a 3 column css layout, with 1 fixed section at the middle and 2 fluid sidebar around it: http://www.uploadup.com/di-UEFI.png middle has 250px width (for example) an
Solution 1:
You can try to use inline-block
s for it. They are used rather rarely, but sometimes they are pretty good for layouts.
So, look at this: http://jsfiddle.net/kizu/UUzE9/ — with inline-block
s you can create layouts with any number of fixed and fluid columns. The algorithm:
- At first, you add the padding equal to the sum of all the fixed columns to the wrapper. In your case —
250px
. - Then, you add
min-width
to the wrapper equal to the sum of all the fluid columns' min-width. - Then, you add
white-space: nowrap
to the wrapper, so the columns won't jump. - And then just add the all columns that you need.
If you need support for IE7 and lesser, there are some additional things to know except for common inline-block
fix:
- You must return
white-space: normal
to the inner child of a column, or the columns won't stay on one line. - There can appear a phantom scroll in IE, maybe there is a better way to remove it, but I just use
overflow: hidden
on some wrapper.
Enjoy :)
Solution 2:
To make this work in IE6/7 without JavaScript, the easiest way to do this is with a table
.
I know, I know. It's not that bad in this case, all considered.
See:http://jsfiddle.net/thirtydot/Q2Qxz/
Tested in IE6/7 + Chrome, and it will just work in all other modern browsers.
HTML:
<tableid="container"cellspacing="0"cellpadding="0"><tr><tdid="left">fluid</td><tdid="mid">fixed</td><tdid="right">fluid</td></tr></table>
CSS:
html, body {
margin: 0;
padding: 0;
border: 0
}
#container {
border: 0;
table-layout: fixed;
width: 100%
}
#containertd {
vertical-align: top
}
#mid {
width: 250px;
background: #ccc
}
#left {
background: #f0f
}
#right {
background: #f0f
}
Post a Comment for "How To Create A 3 Columns Fluid Fixed Fluid Layout?"