JQuery:根据另一个元素改变高度
我有两个DIV:一个DIV根据浏览器动态改变大小(响应式设计),我希望其他DIV根据第一个DIV的高度修改它的高度。 我认为最简单的方法是使用JQuery动态更改高度。
我尝试了以下方法:
$('section#div2').css({height:$(this).css('height').replace($('section#div1 div.div1_container').height()+'px')});
但是,该代码无效。 其他各种版本也不起作用。
我的问题是:如何在不更改给定元素的所有属性的情况下替换单个CSS属性?
编辑:这是动态的第一个DIV编码的方式……
首先是第一个DIV的容器:
position: relative; padding-bottom: 50%; padding-top: 30px; height: 0; overflow: hidden; margin:0 0.7em 0 0.7em;
然后,该容器内的内部对象(可能不相关):
position:absolute; top:0; left:0; width:100%; height:100%;
$('section#div2').css('height', $('section#div1').height()+'px');
用这个:
$('section#div2').height($('section#div1').height());