CSS 將一個頁面平均分成四個部分(div)

來源:互聯網
上載者:User

標籤:head   main   一個   float   code   padding   cti   alt   title   

在項目中遇到需求,資料監控頁面需要同時顯示4個板塊內容,如:

 

 

CSS 如何將一個頁面平均分成四個部分(div)呢?

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>將頁面平均分成四部分</title>    <style type="text/css">        *{            margin: 0;            padding: 0;        }        .main{            width: 100%;            height: 100%;            position: absolute;        }        .quarter-div{            width: 50%;            height: 50%;            float: left;        }        .blue{            background-color: #5BC0DE;        }        .green{            background-color: #5CB85C;        }        .orange{            background-color: #F0AD4E;        }        .yellow{            background-color: #FFC706;        }    </style></head><body>    <div class="main">        <div class="quarter-div blue"></div>        <div class="quarter-div green"></div>        <div class="quarter-div orange"></div>        <div class="quarter-div yellow"></div>    </div></body></html>

如下:

 由於板塊內部架構組建圖表的浮動問題,用上面方法會出問題,改進方法如下

CSS樣式如下:

/*將頁面分為4個部分*/.clearfix:before,.clearfix:after{    display:table;    content:"";}.clearfix:after{    clear:both;}.clearfix{    *zoom:1;}.thewrap{    margin-top: 16px;    padding-left: 20px;    padding-right: 20px;    width: 100%;    box-sizing: border-box;    overflow: auto;}.quarter-div{    width: 50%;    box-sizing: border-box;    float: left;    overflow: auto;}

JS代碼:

<script>    $(function(){        var bodyH = $(window).height();        console.log(bodyH);        var h = bodyH/2-70;        $(".quarter-div .panel-body").height(h);    });</script>

 

CSS 將一個頁面平均分成四個部分(div)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.