How to make div occupy remaining height?

前端 未结 11 1107
遇见更好的自我
遇见更好的自我 2020-11-27 12:49

I have this problem, I have two divs:

<
11条回答
  •  一个人的身影
    2020-11-27 13:12

    I tried with CSS, and or you need to use display: table or you need to use new css that is not yet supported on most browsers (2016).

    So, I wrote a jquery plugin to do it for us, I am happy to share it:

     
    //Credit Efy Teicher
    $(document).ready(function () {
                $(".fillHight").fillHeight();
                $(".fillWidth").fillWidth();
            });
    
            window.onresize = function (event) {
                $(".fillHight").fillHeight();
                $(".fillWidth").fillWidth();
            }
    
            $.fn.fillHeight = function () {
                var siblingsHeight = 0;
                this.siblings("div").each(function () {
                    siblingsHeight = siblingsHeight + $(this).height();
                });
    
                var height = this.parent().height() - siblingsHeight;
                this.height(height);
            };
    
     
            $.fn.fillWidth = function (){
                var siblingsWidth = 0;
                this.siblings("div").each(function () {
                    siblingsWidth  += $(this).width();
                });
    
                var width =this.parent().width() - siblingsWidth;
                this.width(width);
            }
          * {
                box-sizing: border-box;
            }
    
            html {
            }
    
            html, body, .fillParent {
                height: 100%;
                margin: 0;
                padding: 0;
            }
    
    
    no1
    no2 fill
    no3

提交回复
热议问题