Bootstrap解決頁面縮小變形的辦法


bootstrap布局是應用得很廣泛的一種網頁布局方法,例如:我們用一種中間內容很流行的布局分布:3-6-3式布局。代碼如下

<style type="text/css">
body{
width:1350px;
}
header{
background-color:#d9534f;
height:120px;
}
.center{
background-color:#31b0d5;
border:1px solid #ff0000;
height:300px;
margin:0px;
}
footer{
background-color:#f0ad4e;
height:100px;
}
</style>

<header class="col-lg-12 "></header>
<div class="col-lg-12 ">
<div class="col-lg-3 "></div>
<div class="col-lg-6 "></div>
<div class="col-lg-3"></div>
</div>
<footer class="col-lg-12"></footer>

運行之后,頁面正常,效果如下:

但是,當我們把頁面窗口縮小后,發現頁面中間的3個div被擠開了,一個div獨占一行了,效果如下:

不僅中間的div被擠得位置錯亂,網頁的長度還自動加長了,這可不是我們需要的效果,這時,可把每個分區的class屬性同時設置為col-lg col-md col-sm col-xs,自適應每一種大小的屏幕,改動后的代碼如下:

<header class="col-lg-12 col-md-12 col-xs-12 col-sm-12"></header>
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 center"></div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 center"></div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 center"></div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 center"></div>
</div>
<footer class="col-lg-12 col-md-12 col-xs-12 col-sm-12"></footer>

再運行,縮小頁面之后,頁面再不亂排列了,但縮小頁面窗口時,發現頁面變得扁了,效果如下:

這是每個塊區元素沒有寬度所導致的,若此時再給body設置寬度,[width:1350px(屏幕寬度)]則可以避免這種情況,自動生成了滾動條,並讓頁面正常顯示,效果如下:

 


免責聲明!

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



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