javascript - setting min-height via jquery - Stack Overflow

This is the code I'm trying to use in order to set the height of a background div to always cover

This is the code I'm trying to use in order to set the height of a background div to always cover at least the background of the maindiv + the footer I have set up.

var bgheight = $('.maindiv').css("height");
$('#background').css('min-height', bgheight+'75px');

For some reason the code won't even apply to the #background div and I'm starting to run out of ideas.

When I do something like this

var bgheight = $('.maindiv').height();
$('#background').css({'min-height':beheight+'75px'});

The style is applied but the min-height is gigantic, like almost 50000px tall.

Any ideas?

This is the code I'm trying to use in order to set the height of a background div to always cover at least the background of the maindiv + the footer I have set up.

var bgheight = $('.maindiv').css("height");
$('#background').css('min-height', bgheight+'75px');

For some reason the code won't even apply to the #background div and I'm starting to run out of ideas.

When I do something like this

var bgheight = $('.maindiv').height();
$('#background').css({'min-height':beheight+'75px'});

The style is applied but the min-height is gigantic, like almost 50000px tall.

Any ideas?

Share Improve this question edited May 16, 2016 at 15:37 Tushar 87.3k21 gold badges163 silver badges181 bronze badges asked May 16, 2016 at 15:34 RyanRyan 451 silver badge6 bronze badges 1
  • 2 Change bgheight+'75px' ==> (bgheight + 75) + 'px' – Tushar Commented May 16, 2016 at 15:35
Add a ment  | 

1 Answer 1

Reset to default 8

You are making a string concatenation, not a sum.

Try this:

var bgheight = $('.maindiv').height();
$('#background').css({'min-height': (beheight + 75) + 'px'});

To ensure you are not concatenating strings, you can set Number() function.

var bgheight = Number($('.maindiv').height());
$('#background').css({'min-height': (beheight + 75) + 'px'});

OR (two parameters instead of object)

$('#background').css('min-height', (beheight + 75) + 'px');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745347879a4623647.html

相关推荐

  • javascript - setting min-height via jquery - Stack Overflow

    This is the code I'm trying to use in order to set the height of a background div to always cover

    8小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信