【发布时间】:2013-07-10 05:09:05
【问题描述】:
我试图做的是计算浏览器高度,将该数字减少约 20%,然后将该数字分配给元素的高度。问题是元素位于可滚动的 div 中,因此仅分配 height: 80% 将不起作用,因为我希望浏览器高度而不是父 div 高度。不幸的是,另一个问题是我必须使用!important 语法来强制它。
这是我目前所拥有的:
var browserHeight = jQuery(window).height();
var desiredHeight = browserHeight * 0.8;
jQuery('##myID .myClass').attr('style', 'height: 100px !important');
我只需要弄清楚如何将100px 替换为desiredHeight,而不会丢失!important。
如果您能帮助我,我将不胜感激!即使您有不同的(也许更好的)方法。 :)
【问题讨论】:
-
jQuery('#myID .myClass').attr('style', 'height: '+desiredHeight+'px !important');
标签: jquery css styles height attr