CSS: auto height on containing div, 100% height on background div inside containing div

前端 未结 9 992
忘了有多久
忘了有多久 2020-12-22 20:10

The problem, is that I have a content div which stretches its container height-wise (container and content div have auto height).

I want the background container,

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 21:01

    Okay so someone is probably going to slap me for this answer, but I use jQuery to solve all my irritating problems and it turns out that I just used something today to fix a similar issue. Assuming you use jquery:

    $("#content").sibling("#backgroundContainer").css("height",$("#content").outerHeight());
    

    this is untested but I think you can see the concept here. Basically after it is loaded, you can get the height (outerHeight includes padding + borders, innerHeight for the content only). Hope that helps.

    Here is how you bind it to the window resize event:

    $(window).resize(function() {
      $("#content").sibling("#backgroundContainer").css("height",$("#content").outerHeight());
    });
    

提交回复
热议问题