Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery, get div width when overflow: hidden;

Tags:

jquery

css

How can I get a div width when the div is inside another div with "overflow: hidden;" ?

I tried to set overflow as auto and after using $("#divselector").width() but I always get the parent div width!

Ex:

html:

 <div id="content"> 
            <div id="item">content content content ...</div>
 </div>

css:

#content
{            
    width: 760px;
    height: 100%;
    overflow: hidden;
    display: block;
    position: relative;
    cursor: move;
}

Detail: using IE 6 work, but in IE 8 no...

like image 216
Fabio Avatar asked Jun 16 '10 19:06

Fabio


1 Answers

By default, div's will expand to the width of their parent.

If you float your items within the div, the item will no longer expand to the width of the parent.

Add the following to your styles:

#item { float: left; }

See how this works: http://jsbin.com/umabe/edit

like image 190
Mervyn Avatar answered Oct 04 '22 23:10

Mervyn