Amar Syla Amar Syla - 1 year ago 93
CSS Question

Two fixed width divs, and another div with dynamic size between

The title says everything. I want something like this:

enter image description here

The left box should be positioned in the left, the right one in the right. They both should have fixed widths, e.g. 200px. The middle div should take the size between. Its width is not set, but it takes the width that's remaining.


bot bot
Answer Source

Here's a working one.

Use margin: 0 auto; will get your element centered most of the time. (Quick note: your element must have a declared width for this to work.)

The margin: 0 auto; rule is shorthand for 0 top and bottom margin, and automatic left and right margins. Automatic left and right margins work together to push the element into the center of its container.

The margin: 0 auto; setting doesn't work perfectly in every centering situation, but it works in a whole lot of them.
reference: You Can't Float Center with CSS


<div class="leftsidebar">a</div>
<div class="rightsidebar">b</div>
<div class="content">c</div>


height: 608px; 
width: 60px; 
float:left; } 

height: 608px; 
width: 163px; 

width: auto; //or any width that you want
margin:0 auto;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download