Jquery,在溢出时获取div宽度:隐藏;

时间:2022-11-19 13:57:49

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

当div位于“overflow: hidden”的另一个div中时,如何获得div的宽度?吗?

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

我尝试设置溢出为auto,然后使用$(“#divselector”).width(),但是我总是得到父div的宽度!

Ex:

例:

html:

html:

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

css:

css:

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

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

细节:使用IE 6工作,但是在IE 8没有…

1 个解决方案

#1


8  

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

在默认情况下,div会扩展到父div的宽度。

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

如果您将项目放在div中,该项目将不再扩展到父元素的宽度。

Add the following to your styles:

将以下内容添加到您的风格中:

#item { float: left; }

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

查看如何工作:http://jsbin.com/umabe/edit

#1


8  

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

在默认情况下,div会扩展到父div的宽度。

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

如果您将项目放在div中,该项目将不再扩展到父元素的宽度。

Add the following to your styles:

将以下内容添加到您的风格中:

#item { float: left; }

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

查看如何工作:http://jsbin.com/umabe/edit