how to set height of parent of absolutely positioned element to grow/shrink with child

后端 未结 1 888
余生分开走
余生分开走 2020-12-17 03:21

so i have this:

styled like this:

#parent {         


        
相关标签:
1条回答
  • 2020-12-17 03:57

    In CSS the control always flows from top down, so the child's height can be controlled by the parent but not the other way round. You could use the following jquery to achieve what you're after though:

    var resizeParent = function() {
      var child_height = $('#child').height();
      $('#parent').height(child_height);
    };
    
    $(window).resize(function() {
      resizeParent();
    });
    
    $document.ready(function() {
      resizeParent();
    });
    
    0 讨论(0)
提交回复
热议问题