Expand a div to fill the remaining width

flexbox fill remaining horizontal space
css fill remaining width
div fill remaining width
div fill remaining height of parent
html fill width
div fill parent width
flex fill div

I want a two-column div layout, where each one can have variable width e.g.

div {
    float: left;
.second {
    background: #ccc;
<div class="second">View</div>

Expand a div to fill the remaining width, divs will naturally take up 100% width of their container, there is no need to [2] "​overflow: auto;" makes this div take the remaining width */ .content { width: 100%; } All you need is to add display: flex to your style for "Main" and flex-grow: 100  For an up to date proper answer, please change the selected best answer to Adrien Be's response. – edwardtyl Jul 22 '15 at 18:59. I needed the opposite, a fixed width centre div and fluid outside divs.

I just discovered the magic of flex boxes (display: flex). Try this:

  #box {
    display: flex;
  #b {
    flex-grow: 100;
    border: 1px solid green;
<div id='box'>
 <div id='a'>Tree</div>
 <div id='b'>View</div>

Flex boxes give me the control I've wished css had for 15 years. Its finally here! More info: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Make a div fill up the remaining width, <div style='display:inline-block;width:400px;height:200px;background:lime;'> division fills the rest of the space</div>; </div> What is the best way to have a div expand across the entire height of a page, even if there is no content in the div? How can you expand a div to take the remaining width? There are multiple ways: You can do it with Tables (okay, that’s not actually a div, but you could do it with div’s by setting the containers property to table-cell and the inner property to table-row or something like that), you could do it with margins, with overflow or with flex box.

This would be a good example of something that's trivial to do with tables and hard (if not impossible, at least in a cross-browser sense) to do with CSS.

If both the columns were fixed width, this would be easy.

If one of the columns was fixed width, this would be slightly harder but entirely doable.

With both columns variable width, IMHO you need to just use a two-column table.

How to use CSS make a div take up the remaining width of the , Due to the fact that the remaining space gets distributed automatically, we don't need to think about width values anymore, if we want our child elements to fill the​  Expand div to max width when float:left is set because there the left one has a fixed width. Help with div - make div fit the remaining width because I need two columns both aligned to left

Check this solution out

.container {
  width: 100%;
  height: 200px;
  background-color: green;
.sidebar {
  float: left;
  width: 200px;
  height: 200px;
  background-color: yellow;
.content {
  background-color: red;
  height: 200px;
  width: auto;
  margin-left: 200px;
.item {
  width: 25%;
  background-color: blue;
  float: left;
  color: white;
.clearfix {
  clear: both;
<div class="container">
  <div class="clearfix"></div>
  <div class="sidebar">width: 200px</div>

  <div class="content">
    <div class="item">25%</div>
    <div class="item">25%</div>
    <div class="item">25%</div>
    <div class="item">25%</div>

`flex-grow` is weird. Or is it?, fill-available ???. One of life's great mysteries. fit-content. The fit-content value is roughly equivalent to margin-  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. Syntax: width: 100%; Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.

Flexbox solution

This is what the flex-grow property is for.

html, body {
  height: 100%;
.wrapper {
  display: flex;
  height: 100%;
.second {
  flex-grow: 1;
<div class="wrapper">
  <div style="background: #bef;">Tree</div>
  <div class="second" style="background: #faa;">View</div>

CSS Tricks - Width, region and then set the content area to fill up the remaining space like this: In the CSS above, the flex property shorthands the flex-grow,  While the parent div shouldn't expand beyond a width of 960px, the div I called "wide-div" here should fill the entire width of the screen. It contains a single image that is wider than the 960px, and it should set a different background color for the entire width of the screen.

Make a div fill the height of the remaining screen space, The “calc(x - y)” cannot be used as width changes on multiple dimensions (as seen in CSS). How do I make blue div fill remaining width? This article presents three different ways to make a div take up the remaining height. All solutions are CSS only and the pros and cons are outlined too.

Specific "fill remaining width" - HTML & CSS, Format on Save. If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting. Open the browser developer tools and get the width of the first div with the content inside. Then subtract that width from the div its contained in. That remaining width is what you're looking for. Another solution would be to use sass and use a variable to store that math in.

Expand Div Fill Remaining Width - Flexbox, How can you expand a div to take the remaining width? There are multiple ways: You can do it with Tables (okay, that's not actually a div, but  Problem is if there is not enough content to fill the page, I want the footer to stretch to fill the remaining space on the bottom of the page. I have set the body, html to height:100% and if I set the footer div to height:100% it takes the height of the entire browser and makes it THAT high.

  • related stackoverflow.com/a/22719552/759452
  • Either I don't understand the question or I don't understand how you choose the accepted answer, because there both widths and heights are fixed with the inconvenience of overflow hidden
  • Excellent answer! But you're wrong when you say "any overflow value other than auto" will make it a BFC. What you mean is any overflow value other than the default (visible) will make it a BFC. In fact, overflow auto works perfectly too - thats what I'd recommend (just in case you do have relatively positioned elements that might peek out of that div).
  • This article has a nice explanation: colinaarts.com/articles/the-magic-of-overflow-hidden
  • What if the content is big enough to overflow the div ?
  • It is important to note, that the order of the children matters. The floating element with fixed width has to be above the other one. Took me too long to figure out, why it didn't worked for me with switched order.
  • I wrote an answer explaining why a non-visible overflow of all things triggers a BFC, based on responses given by David and Boris, which can be found here: stackoverflow.com/questions/9943503/… Was my interpretation correct?
  • I don't know what you discovered, but your code is not working in latest Chrome jsfiddle.net/fjb548kw/3
  • @YevgeniyAfanasyev I removed the "float:left;" to fix the issue. Thanks for the note!
  • Thank you. Can you please explain why do you have flex-grow: 100; instead of flex-grow: 1;?
  • @YevgeniyAfanasyev No particular reason except that's how I like to do it. It allows me to think in percents so if I could do something like set #a to flex-grow:10 and then I'd set #b to flex-grow: 90 so #a would be 10% of the line's width and #b would be 90% of the line's width. If no other elements have a flex width style, then it doesn't technically matter what you put.
  • @YevgeniyAfanasyev hilarious :P
  • Table won't be very good in a responsive design where you want the right hand column to slide under the left on small devices though.
  • There are some responsive design tricks to work with tables: css-tricks.com/responsive-data-tables