CSS - auto width floated element (expandable float)

brpaz picture brpaz · Aug 11, 2010 · Viewed 21.5k times · Source

I have two floated collumns side by side. The user can hide/collapse one of that collumns. In that case I want the other collumn to expand to fit the entire container.

Is this possible with CSS?

In resume, it's possible to make a float to expand to the size of it's container? Even if the element is floated, if it has width:auto it should expand. At least that´s way I think it should work.

Answer

Simon East picture Simon East · Apr 26, 2012

Nup, I don't think the accepted answer actually works. I was just attempting the same thing, and this is the solution...

.left { 
    float: left;
}
.right {
    overflow: hidden;
    /* don't float this one */
}

Play around with the code here: http://jsfiddle.net/simoneast/qPHgR/2/