flex懸掛式布局處理固定定位的問題


一直以來在webapp的時候經常遇到上下固定定位的問題,然后有一部分內容被遮擋住了,這就很尷尬,每次都要計算padding當前fixed容器的高度,來保證兄弟元素不被遮擋的問題.這個布局主要使用了flex懸掛布局,一些小的技巧以下是源碼部分.

我是頭部
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body{
            max-width: 750px;
            margin: 0 auto;
        }
        *::-webkit-scrollbar {
            display: none;
        }
        #content{
            height: 100vh;
            display: flex;
            flex-direction: column;
            
        }
        .header{
            background: red;
            height: 40px;
        }
        .wrap_body{
            background: rgba(0, 0, 0, 0.4);
            flex: 1;
            overflow-y: scroll;
        
        }
       
        .bottom{
            background: grey;
            height: 40px;
        }
        .center{
            height: 1200px;
            border: 10px;
            margin: 10px;
            border: 1px solid #ccc;
       
        }
        
    </style>
</head>
<body>
    <div id="content">
        <div class="header">444</div>
        <div class="wrap_body">     
            <div class="body">
                <div class="center">
                      
                </div>
                <div class="center">
                      
                </div>
            
            </div>
        </div>
        <div class="bottom">
            我是底部
        </div>
    </div>
</body>
</html>

 

我是底部


免責聲明!

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



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