How to make child divs always fit inside parent div?

后端 未结 11 690
北海茫月
北海茫月 2020-12-08 09:13

My question is if there is a way, without using JavaScript, to cause child divs to extend to the borders of their parent, without exceeding those borders, when you cannot kn

11条回答
  •  情深已故
    2020-12-08 09:33

    For width it's easy, simply remove the width: 100% rule. By default, the div will stretch to fit the parent container.

    Height is not quite so simple. You could do something like the equal height column trick.

    html, body {width:100%;height:100%;margin:0;padding:0;}
    .border {border:1px solid black;}
    .margin { margin:5px;}
    #one {width:500px;height:300px; overflow: hidden;}
    #two {height:50px;}
    #three {width:100px; padding-bottom: 30000px; margin-bottom: -30000px;}
    

提交回复
热议问题