简体   繁体   English

将相同宽度应用于子div作为父div

[英]Apply same width to child divs as parent div

i have one div which contains several divs. 我有一个包含几个div的div。 I changed the parent div width. 我更改了父div宽度。 But because of the divs which are children to the parent div, the width is increasing. 但由于父div的子节点div,宽度增加。 i written the css class like this. 我这样写了css类。

$('#s4-workspace').css({
    'width': '900px'
});

Here s4-workspace is the parent div. 这里s4-workspace是父div。 After applying the above property and when I see in the IE, the width is increasing to 1600px. 应用上述属性后,当我在IE中看到时,宽度增加到1600px。 I want to apply this width to all the child divs. 我想将此宽度应用于所有子div。 Is there any method to achieve such functionality in jquery? 有什么方法可以在jquery中实现这样的功能吗?

i am working in sharepoint designer. 我在sharepoint设计师工作。

You can use width() jquery function to set the width by getting children using children() function. 您可以使用width() jquery函数通过使用children()函数获取子项来设置宽度。

$('#s4-workspace').children().width($('#s4-workspace').width());

Its better to handle it with style sheet instead jquery/javascript. 最好用样式表来代替jquery / javascript来处理它。 Setting width of children in percentage could do it, like 100%. 以百分比设置儿童的宽度可以做到,例如100%。

of course, if any of those children have borders, or padding, or are floated alongside other floats, this approach won't work. 当然,如果这些孩子中的任何一个有边框或填充物,或者与其他花车一起漂浮,这种方法是行不通的。 have you identified why those child elements are sizing to 1600? 你有没有确定为什么这些儿童元素大小到1600?

the width:100%; width:100%; will work fine 会很好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM