使用jQuery从CSS获取calc-value

时间:2015-04-08 08:55:45

标签: jquery css

我希望div具有min-height = width。这可以用css来完成,但是我还有其他的事情会阻止height = 0padding = 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);

2 个答案:

答案 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