获取没有滚动条宽度的Div宽度 [英] Get the Div width without the scroll Bar width
问题描述
我在这里遇到问题。这里有两个divdiv1和div2。这里我想根据div2宽度调整div1宽度。我的要求是div1不应该包含scrollBar的宽度,即我应该设置div1
的高度,不包括div2中scrollBar的宽度。我想要一个jquery函数来查找宽度并减小div1的宽度..
样本要求如下所示
I am having a issue here. There are two div's here "div1" and "div2". Here I want to adjust the "div1" width according to the "div2" width. My requirement is The width of the scrollBar should not be included for the "div1" i.e i should set the height of the "div1" excluding the width of the scrollBar in "div2". I want a jquery function to find the width and to reduce the width of "div1".. Sample requirement is shown below
<div class="div1"></div>
<div class="div2">HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello</div>
css
css
.div1
{
width:100px;
height:100px;
border:1px solid black;
}
.div2
{
width:100px;
height:300px;
border:1px solid black;
overflow:auto;
word-break:break-all;
}
小提琴演示在这里
< a href =http://jsfiddle.net/d34Fk/ =nofollow noreferrer> 小提琴
推荐答案
请参阅: http://jsfiddle.net/d34Fk/5/
jQuery:
var width = $('.div2')[0]['clientWidth'];
$('.div1').css({'width':width+'px'});
这篇关于获取没有滚动条宽度的Div宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!