有一個高度自適應的div,里面有兩個div,一個高度100px,希望另一個填滿剩下的高度。


box-sizing方案     和 absolute position方案

       1.外層box-sizing: border-box; 同時設置padding: 100px 0 0

       2.內層100像素高的元素向上移動100像素,或使用absolute定位防止占據空間;

       3.另一個元素直接height: 100%;       代碼如下   

       <!DOCTYPE html>
       <html lang="en">
       <head>
      <meta charset="UTF-8">
      <title>Title</title>
      <style type="text/css">

html,
body { height: 100%; padding: 0; margin: 0; }
.outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; }
.A { height: 100px; margin: -100px 0 0; background: #BBE8F2; }
.B { height: 100%; background: #D9C666; }

</style>


</head>
<body>
<div class="outer">
<div class="A"></div>
<div class="B"></div>
</div>

</body>
</html>

    第二種css  代碼  如下 :

html, body { height: 100%; padding: 0; margin: 0; }

.outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; position: relative; }

.A { height: 100px; background: #BBE8F2; position: absolute; top: 0 ; left: 0 ; width: 100%; }

.B { height: 100%; background: #D9C666; }

  第三種css  代碼 如下:

html, body { height: 100%; padding: 0; margin: 0; }

.outer { height: 100%; position: relative; }

.A { height: 100px; background: #BBE8F2; }

.B { background: #D9C666; width: 100%; position: absolute; top: 100px ; left: 0 ; bottom: 0; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM