我希望div具有min-height = width。这可以用css来完成,但是我还有其他的事情会阻止height = 0
,padding = 100%
技巧,所以我使用jQuery
我在获取calc-css值时遇到问题,它只是0px
,我想知道是否有解决方法?
CSS
.box{
width: calc(50% - 10px);
height: auto;
}
的jQuery
var box = $('.box');
var box_w = box.width();
box.css('min-height', box_w);
答案 0 :(得分:1)
您的问题似乎在这里:
var box = $('.box');
var box_w = lbInfo.width(); // <----you need to change 'lbInfo' to 'box'
我想你想改变它:
var box = $('.box');
var box_w = box.css('width'); // because you have set the width property in css
lbInfo.css('min-height', box_w);
答案 1 :(得分:1)
我会这样做:
$(".box").css("min-height", function() {
return $(this).width(); // or outerWidth() or $(this).css('width');
});
这种方式,如果您有多个.box
,则他们的min-height
设置为相应的width