How to make child div scrollable when it exceeds parent height?

后端 未结 3 914
情书的邮戳
情书的邮戳 2021-02-02 11:48

I have 2 child divs nested in a parent div in row-column pattern: the parent is a column, and the children are rows.\"enter

3条回答
  •  萌比男神i
    2021-02-02 12:14

    Overflow only works when you give it a value to overflow when greater than. Your value is relative to how big the top is, so using jQuery, grab that value then subtract from the parent.

    $(document).ready(function() {
      $(".child2").css("max-height", ($(".parent").height()-$(".child1").height()));
    });
    

    and add overflow's to the children

    .child1 {
        background-color: red;
        overflow: hidden;
    }
    
    .child2 {
        background-color: blue;
        overflow: auto;
    }
    

    http://jsfiddle.net/m9goxrbk/

提交回复
热议问题