Bootstrap 提供了一套响应式、移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多列。

网页设计中的网格布局作用:组织内容,让网站易于浏览,并降低用户端的负载。

Grid System

Bootstrap 包含了一个响应式的、移动设备优先的、不固定的网格系统,可以随着设备或视口大小的增加而适当地扩展到 12 列。它包含了用于简单的布局选项的预定义类,也包含了用于生成更多语义布局的功能强大的混合类。

移动设备优先策略:

1.基础的 CSS 是移动设备优先,媒体查询是针对于平板电脑、台式电脑。

2.随着屏幕大小的增加而添加元素。

3.优先设计更小的宽度。

Grid System 工作原理

1.行必须放置在 .container class 内,以便获得适当的对齐(alignment)和内边距(padding)。

2.使用行来创建列的水平组。

3.内容应该放置在列内,且唯有列可以是行的直接子元素。

4.预定义的网格类,比如 .row 和 .col-xs-4,可用于快速创建网格布局。LESS 混合类可用于更多语义布局。

5.列通过内边距(padding)来创建列内容之间的间隙。该内边距是通过 .rows 上的外边距(margin)取负,表示第一列和最后一列的行偏移。

6.网格系统是通过指定您想要横跨的十二个可用的列来创建的。例如,要创建三个相等的列,则使用三个 .col-xs-4

媒体查询

媒体查询是非常别致的"有条件的 CSS 规则"。它只适用于一些基于某些规定条件的 CSS。如果满足那些条件,则应用相应的样式。

/* 超小设备(手机,小于 768px) */
/* Bootstrap 中默认情况下没有媒体查询 */ /* 小型设备(平板电脑,768px 起) */
@media (min-width: @screen-sm-min) { ... } /* 中型设备(台式电脑,992px 起) */
@media (min-width: @screen-md-min) { ... } /* 大型设备(大台式电脑,1200px 起) */
@media (min-width: @screen-lg-min) { ... }

有时候也会在媒体查询代码中包含 max-width,从而将 CSS 的影响限制在更小范围的屏幕大小之内。

@media (max-width: @screen-xs-max) { ... }
@media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
@media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
@media (min-width: @screen-lg-min) { ... }

网格选项

.col-xs-  超小设备手机(<768px)

.col-sm- 小型设备平板电脑(≥768px)

.col-md- 中型设备台式电脑(≥992px)

.col-lg-   大型设备台式电脑(≥1200px)

代码

01 页面居中显示的容器

<!DOCTYPE html>
<html>
<head> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"><!--告诉IE浏览器用最新的引擎-->
<meta name="viewport" content="width=device-width, initial-scale=1"><!--响应式布局-->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" /><!--bootstrap样式--> <title></title> </head>
<body> <div class="container">
<h1 class="page-header">主体</h1>
<p>Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.</p>
</div> <script src="Script/jquery-1.8.3.js"></script><!--Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边-->
<script src="bootstrap/js/bootstrap.min.js"></script><!--Bootstrap 的所有 JavaScript 插件-->
</body>
</html>

class:page-header,container

.page-header {
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eee;
} .container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
@media (min-width: 768px) {
.container {
width: 750px;
}
}
@media (min-width: 992px) {
.container {
width: 970px;
}
}
@media (min-width: 1200px) {
.container {
width: 1170px;
}
}

02 网格类

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" /> <title></title> </head>
<body> <div class="container">
<div class="row">
<!--
col-lg-6 >=1200px
col-md-8 >=992px
col-sm-6 >=768px
col-xs-6 <798px
-->
<div class="col-md-8 col-sm-6">
<h1 class="page-header">主体</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-4 col-sm-6">
<h1 class="page-header">边栏</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
</div>
</div> <script src="Script/jquery-1.8.3.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

03 混合使用网格类

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" /> <title></title> </head>
<body> <div class="container">
<div class="row">
<!--
col-lg-6 >=1200px
col-md-8 >=992px
col-sm-6 >=768px
col-xs-6 <798px
-->
<div class="col-md-9 col-sm-8 col-xs-6 col-lg-10">
<h1 class="page-header">主体</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-3 col-sm-4 col-xs-6 col-lg-2">
<h1 class="page-header">边栏</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
</div>
</div> <script src="Script/jquery-1.8.3.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

04 push和pull

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" /> <title></title> </head>
<body> <div class="container">
<div class="row">
<div class="col-md-9 col-md-push-3"><!--col-md-push-3:中等尺寸往右推3个网格-->
<h1 class="page-header">主体</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-3 col-md-pull-9"><!--col-md-pull-9:中等尺寸往左拉9个网格-->
<h1 class="page-header">边栏</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
</div>
</div> <script src="Script/jquery-1.8.3.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

05 嵌套的布局

class:clearfix 清除浮动  or 每行网格都放在 class:row中的div中

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" /> <title></title> </head>
<body> <div class="container">
<div class="row">
<div class="col-md-8">
<h1 class="page-header">主体</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
<div class="row">
<div class="col-md-4">
<h1 class="page-header">区块1</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-4">
<h1 class="page-header">区块2</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-4">
<h1 class="page-header">区块3</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="clearfix"></div>
<div class="col-md-6">
<h1 class="page-header">区块4</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
<div class="col-md-6">
<h1 class="page-header">区块5</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
</div>
</div>
<div class="col-md-4">
<h1 class="page-header">边栏</h1>
<p>
Use this document as a way to quickly start any new project.
All you get is this text and a mostly barebones HTML document.
</p>
</div>
</div>
</div> <script src="Script/jquery-1.8.3.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

Bootstrap3基础教程 02 网格布局的更多相关文章

  1. bootstrap学习总结-02 网格布局

    1  网格布局 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. <!DOCTYPE html> ...

  2. GStreamer基础教程02 - 基本概念

    摘要 在 Gstreamer基础教程01 - Hello World中,我们介绍了如何快速的通过一个字符串创建一个简单的pipeline.为了能够更好的控制pipline中的element,我们需要单 ...

  3. Python基础教程-02

    <Python基础教程> 第3章 使用字符串 字符串方法find返回的并非布尔值.如果find像这样返回0,就意味着它在索引0处找到 了指定的子串 join可合并一个字符串列表,不能合并数 ...

  4. Bootstrap3基础教程 01 概述

    移动设备优先是 Bootstrap 3 的最显著的变化. 基础的页面: <!DOCTYPE html> <html> <head> <meta charset ...

  5. Bootstrap3基础 栅格系统 页面布局随 浏览器大小的变化而变化

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  6. 【GStreamer开发】GStreamer基础教程02——GStreamer概念

    上一个教程演示了如何自动生成一个pipeline.这次我们打算用一个个element来手动搭建一个pipeline.我们这个教程会演示: 1. 什么是GStreamer的element以及如何建立一个 ...

  7. Bootstrap3基础教程 03 导航栏

    Bootstrap导航栏 创建一个默认的导航栏的步骤如下: 1.向 <nav> 标签添加 class .navbar..navbar-default. 2.向上面的元素添加 role=&q ...

  8. 图形学基础教程02--顶点数据和SHADER寄存器 (带演示程序)

    本文系原创,欢迎转载,请标明链接 http://www.cnblogs.com/luming1979 有问题欢迎加qq群讨论:366239605

  9. 02网格布局Gridlayout

    <span style="font-size:18px;"><?xml version="1.0" encoding="utf-8& ...

随机推荐

  1. 在Ubuntu 16.04 LTS下编译安装OpenCV 4.1.1

    目录 一 安装前的准备 二 编译并安装OpenCV 4.1.1 注:原创不易,转载请务必注明原作者和出处,感谢支持! OpenCV目前(2019-8-1)的最新版本为4.1.1.本文将介绍如何在Ubu ...

  2. ossfs挂载oss到ECS本地并设置权限

    下载ossfs wget https://github.com/aliyun/ossfs/releases/download/v1.80.2/ossfs_1.80.2_ubuntu16.04_amd6 ...

  3. Python - 排序( 插入, 冒泡, 快速, 二分 )

    插入排序 算法分析 两次循环, 大循环对队列中的每一个元素拿出来作为小循环的裁定对象 小循环对堆当前循环对象在有序队列中寻找插入的位置 性能参数 空间复杂度 O(1) 时间复杂度 O(n^2) 详细代 ...

  4. 2.使用kubeadm快速搭建k8s集群

    准备工作: 时间同步 systemctl stop iptables.servicesystemctl stop firewalld.service 安装docker wget https://mir ...

  5. 图片滚动js代码

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  6. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-4.在线教育后台数据库设计

    笔记 4.在线教育后台数据库设计     简介:讲解后端数据库设计    ,字段冗余的好处,及常见注意事项 1.数据库设计:          er图:          实体对象:矩形        ...

  7. R语言与概率统计(二) 假设检验

    > ####################5.2 > X<-c(159, 280, 101, 212, 224, 379, 179, 264, + 222, 362, 168, 2 ...

  8. c语言实行泛型hashmap

    代码出处:A simple string hashmap in C  https://github.com/petewarden/c_hashmap main.c (main2是官方源代码,main是 ...

  9. HBase管理与监控——强制删除表

    在用phoenix创建Hbase表时,有时会提示创建失败,发现Hbase中又已创建成功, 但这些表在进行enable.disable.drop都无效,也无法删除: hbase(main)::> ...

  10. java中,有关移位运算符的有关讨论

    java中有三种移位运算符 <<      :     左移运算符,num << 1,相当于num乘以2 >>      :     右移运算符,num >& ...