Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - auto width floated element (expandable float)

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.

like image 308
brpaz Avatar asked Aug 11 '10 10:08

brpaz


People also ask

Is float still used in CSS?

CSS float is still relevant. We should just use it in the right context! This article discusses the history of CSS float and demonstrates several ways that float can be used in modern web design to achieve creative text layouts and stunning design elements.

How do I make a div float over a page?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

How do you apply a float in CSS?

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).


2 Answers

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/

like image 190
Simon East Avatar answered Oct 07 '22 20:10

Simon East


set overflow:auto; height:auto; for floatet element :)

like image 20
FARHAD AFSAR Avatar answered Oct 07 '22 18:10

FARHAD AFSAR