JSFIDDLE
EDIT: Trying to achieve the opposite of this.
(instead of 2 fixed-width divs on the sides and one fluid-width div in the middle,
I'm trying to get 2 fluid-width divs on the sides and one div centered in the middle)
I have 3 divs: A, B, and C.
B needs to sit centered between A and C.
What I'm currently doing is pretty much matching what's going on above. But, if A, B, and C's container has an odd width, some browsers are rounding A and C's widths down and others up (leaving C 1px too long and 1px too short, respectively).
notice the extra pixel to the right of C
notice the space to the right of C is a pixel thinner.
I don't care how many nested divs I need, but I've been spending way too much time on this! If someone already has a sure-fire solution to this problem, please share!
notes:
- A, B, and C's parent can't have overflow hidden.
- A, B, and C can't overlap (they have translucent png's)
This is my starting point: JSFIDDLE
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format.
Here are two ways that work, both with caveats (warning, both require a wrapper):
<section class="wrapper">
<div class="column" id="a"></div>
<div class="column" id="b"></div>
<div class="column" id="c"></div>
</section>
.column {
height: 3em;
}
#a {
background-color: red;
}
#b {
background-color: green;
}
#c {
background-color: blue;
}
#b {
width: 50px;
}
.wrapper {
display:box;
box-orient:horizontal;
box-align:stretch;
}
#a, #b {
box-flex:1.0;
}
Caveat: Only supported (so far) in Firefox and Webkit (Chrome/Safari), both requiring prefixed rules. The above is what it will be someday.
Here is a demo with prefixes: http://jsfiddle.net/crazytonyi/cBVTE/
.wrapper {
display: table;
width: 100%;
table-layout: fixed;
}
.column {
display: table-cell;
}
Caveats: IE didn't start supporting this display type until 7 or 8. On the other hand, worrying about users on older versions of IE is like worrying about people who still turn off cookies and javascript. Either they catch up or get used to pages breaking. End the pandering!
Here's a demo using the above: http://jsfiddle.net/crazytonyi/kM46h/
In both cases, no floats or positioning needed, just willingness to give the middle finger to older browsers. How old depends on which method you choose.
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