文章目录

  • 什么是 Bootstrap 网格系统(Grid System)?
  • Bootstrap 网格系统(Grid System)的工作原理
  • 网格选项
  • 响应式的列重置
  • 偏移列
  • 嵌套列
  • 列排序

什么是 Bootstrap 网格系统(Grid System)?

移动设备优先策略

  • 内容
    决定什么是最重要的。
  • 布局
    优先设计更小的宽度。
    基础的 CSS 是移动设备优先,媒体查询是针对于平板电脑、台式电脑。
  • 渐进增强
    随着屏幕大小的增加而添加元素。

Bootstrap 网格系统(Grid System)的工作原理

网格系统通过一系列包含内容的行和列来创建页面布局。下面列出了 Bootstrap 网格系统是如何工作的:

  • 行必须放置在 .container class 内,以便获得适当的对齐(alignment)和内边距(padding)。
  • 使用行来创建列的水平组。
  • 内容应该放置在列内,且唯有列可以是行的直接子元素。
  • 预定义的网格类,比如 .row 和 .col-xs-4,可用于快速创建网格布局。LESS 混合类可用于更多语义布局。
  • 列通过内边距(padding)来创建列内容之间的间隙。该内边距是通过 .rows 上的外边距(margin)取负,表示第一列和最后一列的行偏移。
  • 网格系统是通过指定您想要横跨的十二个可用的列来创建的。例如,要创建三个相等的列,则使用三个 .col-xs-4。

网格选项


基本的网格结构

<div class="container"><div class="row"><div class="col-*-*"></div><div class="col-*-*"></div>      </div><div class="row">...</div>
</div>
<div class="container">....

响应式的列重置

以下实例包含了4个网格,但是我们在小设备浏览时无法确定网格显示的位置。

为了解决这个问题,可以使用 .clearfix class和 响应式实用工具来解决,如下面实例所示:

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"> <title>Bootstrap 实例 - 响应式的列重置</title><link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body><div class="container"><div class="row" ><div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
         box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p></div><div class="col-xs-6 col-sm-3" style="background-color: #dedef8;box-shadow:
         inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut. </p></div><div class="clearfix visible-xs"></div><div class="col-xs-6 col-sm-3" style="background-color: #dedef8;
         box-shadow:inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p></div><div class="col-xs-6 col-sm-3" style="background-color: #dedef8;box-shadow:
         inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </p></div></div>
</div></body>
</html>

偏移列

偏移是一个用于更专业的布局的有用功能。它们可用来给列腾出更多的空间。例如,.col-xs-* 类不支持偏移,但是它们可以简单地通过使用一个空的单元格来实现该效果。

为了在大屏幕显示器上使用偏移,请使用 .col-md-offset-* 类。这些类会把一个列的左外边距(margin)增加 * 列,其中 * 范围是从 1 到 11。

在下面的实例中,我们有 <div class="col-md-6">..</div>,我们将使用 .col-md-offset-3 class 来居中这个 div

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"> <title>Bootstrap 实例 - 偏移列</title><link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body><div class="container"><h1>Hello, world!</h1><div class="row" ><div class="col-md-6 col-md-offset-3" style="background-color: #dedef8;box-shadow:
         inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p></div></div>
</div></body>
</html>

嵌套列

为了在内容中嵌套默认的网格,请添加一个新的 .row,并在一个已有的 .col-md-* 列内添加一组 .col-md-* 列。被嵌套的行应包含一组列,这组列个数不能超过12(其实,没有要求你必须占满12列)。

在下面的实例中,布局有两个列,第二列被分为两行四个盒子。

<!DOCTYPE html>
<html>
<head><meta charset="utf-8"> <title>Bootstrap 实例 - 嵌套列</title><link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body><div class="container"><h1>Hello, world!</h1><div class="row"><div class="col-md-3" style="background-color: #dedef8;box-shadow:
         inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><h4>第一列</h4><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p></div><div class="col-md-9" style="background-color: #dedef8;box-shadow:
         inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><h4>第二列 - 分为四个盒子</h4><div class="row"><div class="col-md-6" style="background-color: #B18904;
               box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Consectetur art party Tonx culpa semiotics. Pinterest assumenda minim organic quis.</p></div><div class="col-md-6" style="background-color: #B18904;
               box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div></div><div class="row"><div class="col-md-6" style="background-color: #B18904;
               box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p></div>   <div class="col-md-6" style="background-color: #B18904;
               box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim.</p></div></div></div></div></div></body>
</html>

列排序

Bootstrap 网格系统另一个完美的特性,就是您可以很容易地以一种顺序编写列,然后以另一种顺序显示列。

您可以很轻易地改变带有 .col-md-push-*.col-md-pull-* 类的内置网格列的顺序,其中 * 范围是从 1 到 11。

在下面的实例中,我们有两列布局,左列很窄,作为侧边栏。我们将使用 .col-md-push-*.col-md-pull-* 类来互换这两列的顺序。

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>Bootstrap 实例 - 列排序</title><link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script><script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body><div class="container"><h1>Hello, world!</h1><div class="row"><p>排序前</p><div class="col-md-4" style="background-color: #dedef8;
         box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">我在左边</div><div class="col-md-8" style="background-color: #dedef8;
         box-shadow: inset 1px -1px 1px #444, inset -1px 1px 1px #444;">我在右边</div></div><br><div class="row"><p>排序后</p><div class="col-md-4 col-md-push-8" style="background-color: #dedef8;
         box-shadow: inset 1px -1px 1px #444,
         inset -1px 1px 1px #444;">我在左边</div><div class="col-md-8 col-md-pull-4" style="background-color: #dedef8;
         box-shadow: inset 1px -1px 1px #444,
         inset -1px 1px 1px #444;">我在右边</div></div></div></body>
</html>

【Bootstrap】(二)Bootstrap 网格系统相关推荐

  1. JavaEE中级.20190601.Bootstrap(Bootstrap介绍.Bootstrap 特点.下载与使用.布局容器.栅格网格系统.排版)

    一.Bootstrap介绍 1.官网:http://getbootstrap.com/          中文网:http://www.bootcss.com/ Bootstrap是一套现成的CSS样 ...

  2. Bootstrap中的网格系统

    实现原理 网格系统的实现原理非常简单,仅仅是通过定义容器大小,平分12份(也有平分成24份或32份,但12份是最常见的),再调整内外边距,最后结合媒体查询,就制作出了强大的响应式网格系统.Bootst ...

  3. 【Bootstrap】bootstrap入门之栅格布局、弹性布局、组件类_02

    目录 一.响应式网页 二.Bootstrap 三.栅格布局 1.语法 2.源码解析 3.不带数字的col类 4.栅格的列偏移 四.弹性布局 五.关于input 的样式

  4. 【Bootstrap】bootstrap入门之媒体查询技术、样式类_01

    目录 一.响应式网页 1.编写响应式网页 2.使用媒体查询 二.Bootstrap 1.如何使用boot 2.全局样式 (1) 容器相关 (2) 按钮相关 (3) 图片相关 (4) 文本相关 (5) ...

  5. 【Bootstrap】Bootstrap框架认识和使用

    [Bootstrap]Bootstrap框架认识和使用 Bootstrap是一个Web开发的框架 百度百科: Bootstrap是美国Twitter公司的设计师Mark Otto和Jacob Thor ...

  6. Bootstrap -- 初见 Bootstrap

    Bootstrap -- 初见 Bootstrap Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的. ...

  7. Bootstrap笔记(二) 认识网格系统

    认识网格系统 介绍 网格选项 断点(Breakpoint) 容器(Container) 介绍 Bootstrap网格系统是透过横向的row(列)和直向的column(行)来设计网页版面,他将网页宽度平 ...

  8. Bootstrap布局之网格系统

    一.Bootstrap网格系统工作原理 Bootstrap的网格系统是指将页面布局划分为等宽的列. 随着屏幕或视口尺寸的增加,系统会自动分为1~12列. 网格系统用于通过一系列的行(row)与列(co ...

  9. Bootstrap笔记(四) 网格系统 - column的宽度、位移、换行与顺序

    网格系统 - column的宽度.位移.换行与顺序 column的宽度 column的位移 将column换到新行 column的顺序 column的宽度 我们可以使用Bootstrap提供的 .co ...

  10. Bootstrap笔记(三) 网格系统 - row与column的对齐方式

    网格系统 - row与column的对齐方式 row的垂直对齐方式 column的水平对齐方式 row的垂直对齐方式 我们可以使用 .align-items-* 类别设定row的垂直对齐方式. .al ...

最新文章

  1. Spring Boot实战:异步编程指南
  2. 新书-JavaScript高级程序设计:第2版(预订中,估价)
  3. json pandas 内存溢出_python-将多个JSON记录读取到Pandas数据框中
  4. SD2C大会,JavaScript + Delphi + ErLang 讲演相关资料完全公开!
  5. 3. Qt Creator
  6. Windows Mobile 6.5 新功能widget开发
  7. mysql5.7.26修改账号密码_修改mysql5.7的用户密码
  8. mfc formview中的关闭视图函数_VC|API消息处理(回调函数+分支语句)与MFC中的消息映射函数...
  9. validators配置要点及No result defined for action报错解决方案
  10. (转)“跑批”发展编年史
  11. Code snippet of the day : Get Chinese Spell in C#
  12. 计算机主机的系统安装方法,电脑安装系统的最全教程,系统安装教程详解
  13. 联想计算机不能进入系统桌面,联想笔记本电脑进不了桌面怎么办
  14. 【T3】打印单据(非新打印)表头显示不全
  15. 飞机一般是什么操作系统?
  16. Population and carrying capacity 的第二阶段 :Crowding affects lifetime.
  17. 线性代数学习笔记——行列式(针对期末与考研)
  18. 统计套利 Statistical arbitrage
  19. 按位与,按位或和按位异或是否都满足交换律和结合律?
  20. 安装金山WPS2013造成的HTML5 file.type值异常

热门文章

  1. 2022最新Ripro日主题9.0升级修正源码+两个美化包和插件
  2. 现在计算机常用的分辨率,pc端常用电脑屏幕 ((响应式PC端媒体查询)电脑屏幕分辨率尺寸大全)...
  3. Hadoop常用的操作指令速查和讲解
  4. 单臂路由配置(H3C)
  5. 计算机软件安装的实训报告,计算机常用工具软件实训报告
  6. Nuxt3 简单集成 GoogleMap
  7. 数据源(Data Source
  8. win7设置wifi热点_如何给笔记本电脑设置wifi热点,学学马上就会!从此不求人!...
  9. win7设置wifi热点步骤
  10. 21秋哈工大近世代数期末试题