I have 2 divs: one in the left side and one in the right side of my page. The one in the left side has fixed width and I want the one of the right side to fill the remaining space.
#search {
width: 160px;
height: 25px;
float: left;
background-color: #ffffff;
}
#navigation {
width: 780px;
float: left;
background-color: #A53030;
}
<div id="search">Text</div>
<div id="navigation">Navigation</div>
If you don't need compatibility with older versions of certain browsers (IE
108 or less for example) you can use thecalc()
CSS function:I had a similar problem and I found the solution here: https://stackoverflow.com/a/16909141/3934886
The solution is for a fixed center div and liquid side columns.
If you want a fixed left column, just change the formula accordingly.
You can use the Grid CSS properties, is the most clear, clean and intuitive way structure your boxes.
This seems to accomplish what you're going for.
The problem that I found with Boushley's answer is that if the right column is longer than the left it will just wrap around the left and resume filling the whole space. This is not the behavior I was looking for. After searching through lots of 'solutions' I found this awesome tutorial on creating three column pages.
The author offer's three different ways, one fixed width, one with three variable columns and one with fixed outer columns and a variable width middle. Much more elegant and effective than other examples I found. Significantly improved my understanding of CSS layout.
Basically, in the simple case above, float the first column left and give it a fixed width. Then give the column on the right a left-margin that is a little wider than the first column. That's it. Done. Ala Boushley's code:
Here's a demo in Stack Snippets & jsFiddle
With Boushley's example the left column holds the other column to the right. As soon as the left column ends the right begins filling the whole space again. Here the right column simply aligns further into the page and the left column occupies it's big fat margin. No flow interactions needed.
I have a very simple solution for this ! //HTML
//CSS
Link: http://jsfiddle.net/MHeqG/