栅格系统

前些天学习了bootstrap,把其中的栅格系统整理出来,如有错误,欢迎指正。

 

概要,栅格系统针对pc,pad,移动端开发出响应式web页面,根据不同屏幕分辨率有针对不同的解决方法。

(0.1, 屏幕设备尺寸大于1200px 选择col-lg

(0.2. 屏幕设备尺寸在970px到1200px 选择col-md

(0.3. 屏幕设备尺寸在768px到970px 选择col-sm

(0.4. 屏幕设备尺寸小于768px 选择col-xs

 

1.栅格系统把页面分为12栏(最多12栏),如下:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maxinum-scale,user-scalable=no">
    <title>栅格系统</title>
    <link rel="stylesheet" href="library/bootstrap.min.css">
    <style>
                         .a{
                             height: 50px;
                             border: 1px red solid;
                             background: pink;
                         } 
    </style>
</head>
<body>
    <div class="container a">
        <div class="row">
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
            <div class="col-md-1 a">1</div>
        </div>

        <div class="row">
            <div class="col-md-3 a">3</div>
            <div class="col-md-9 a">9</div>
        </div>
    </div>


<script src="library/jq.js"></script>    
<script src="library/bootstrap.min.js"></script>
</body>
</html>

 

(2.1,  col-md-1为一栏,合计12栏布满一个"横排",md后尾随的数字为分配的栏数,(col-lg,col-sm,col-xs同理)

 

3.在不同屏幕分辨率的设备下,所呈现的页面为对应的"栅格式栏数页面",从而实现响应式布局,如下代码:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maxinum-scale,user-scalable=no">
    <title>栅格系统</title>
    <link rel="stylesheet" href="library/bootstrap.min.css">
    <style>
                         .a{
                             height: 50px;
                             border: 1px red solid;
                             background: pink;
                         } 
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>
            <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 a">1</div>            
        </div>
    </div>

<script src="library/jq.js"></script>    
<script src="library/bootstrap.min.js"></script>
</body>
</html>

(3.1,上图代码表示在屏幕设备尺寸大于1200px时,一个横排有四大栏,一个大栏有三小栏,小栏共计12栏,

(3.2,表示在屏幕设备尺寸在970px到1200px时(可以先看为浏览器缩小至这个阶段时),一个横排有三大栏,一个大栏有四小栏,小栏共计12栏,

(3.2,表示在屏幕设备尺寸在768px到970px时(可以先看为浏览器缩小至这个阶段时),一个横排有二大栏,一个大栏有六小栏,小栏共计12栏,

(3.2,表示在屏幕设备尺寸小于768px时(可以先看为浏览器缩小至这个阶段时),一个横排有一大栏,一个大栏有十二小栏,小栏共计12栏,

 

4,栅格系统里的列偏移,嵌套和交换位置

(4.1,列偏移

        <div class="row">            
             <div class="col-md-8 a">8</div>
             <div class="col-md-3 col-md-offset-1 a">3</div>    <!-- 列向右偏移一位  -->            
        </div>

(4.2,嵌套

    <div class="row">       <!-- 嵌套  -->        
            <div class="col-md-9 a" style="padding:0;">
                <div class="col-md-4 a"></div>
                <div class="col-md-4 a"></div>
                <div class="col-md-4 a"></div>
            </div>
            <div class="col-md-3 a">3</div>                
    </div>

(4.3,交换位置

    <div class="row">         <!-- 交换位置  -->        
            <div class="col-md-9 col-md-push-3 a">9</div>            <!-- push,向右移  -->
            <div class="col-md-3 col-md-pull-9 a">3</div>            <!-- pull,向左移  -->
    </div>

 

posted @ 2016-06-12 10:00  小陈小陈  阅读(763)  评论(0编辑  收藏  举报