` 标签标记用户通过键盘输入的内容。=
14 |
15 |
16 |
17 | ```
18 | To switch directories, type cd followed by the name of the directory.
19 | To edit settings, press ctrl + ,
20 | ```
21 | ###代码块
22 | 多行代码可以使用 `` 标签。为了正确的展示代码,注意将尖括号做转义处理。
23 |
24 |
25 |
26 | ```
27 | <p>Sample text here...</p>
28 | ```
29 | 还可以使用 `.pre-scrollable` 类,其作用是设置 max-height 为 350px ,并在垂直方向展示滚动条。
30 |
31 | 变量
32 | 通过 `` 标签标记变量。
33 |
34 |
35 |
36 |
37 | ```
38 | y = m x + b
39 | ```
40 | 程序输出
41 | 通过 标签来标记程序输出的内容。
42 |
43 |
44 |
45 |
46 | ```
47 | This text is meant to be treated as sample output from a computer program.
48 | ```
49 |
--------------------------------------------------------------------------------
/getting-started/compiling-css-and-javascript.md:
--------------------------------------------------------------------------------
1 | # 编译 CSS 和 JavaScript 文件
2 |
3 | Bootstrap 使用 Grunt 作为编译系统,并且对外提供了一些方便的方法用于编译整个框架。下面讲解的就是如何编译源码、运行测试用例等内容。
4 |
5 | ## 安装 Grunt
6 | 安装 Grunt 前,你需要首先下载并安装 node.js (npm 已经包含在内)。npm 是 node packaged modules 的简称,它的作用是基于 node.js 管理扩展包之间的依赖关系。
7 |
8 | 然后在命令行中输入以下命令:
9 | 在全局环境中安装 `grunt-cli` :`npm install -g grunt-cli `。
10 | 进入 `/bootstrap/` 根目录,然后执行 `npm install` 命令。npm 将读取 `package.json` 文件并自动安装此文件中列出的所有被依赖的扩展包。
11 | 上述步骤完成后,你就可以运行 Bootstrap 所提供的各个 Grunt 命令了。
12 |
13 | ## 可用的 Grunt 命令
14 | `grunt dist` (仅编译 CSS 和 JavaScript 文件)
15 | 重新生成 `/dist/` 目录,并将编译压缩后的 CSS 和 JavaScript 文件放入这个目录中。作为一名 Bootstrap 用户,大部分情况下你只需要执行这一个命令。
16 |
17 | `grunt watch` (监测文件的改变,并运行指定的 Grunt 任务)
18 | 监测 Less 源码文件的改变,并自动重新将其编译为 CSS 文件。
19 |
20 | `grunt test` (运行测试用例)
21 | 在 PhantomJS 环境中运行 JSHint 和 QUnit 自动化测试用例。
22 |
23 | `grunt docs` (编译并测试文档中的资源文件)
24 | 编译并测试 CSS、JavaScript 和其他资源文件。在本地环境下通过 jekyll serve 运行 Bootstrap 文档时需要用到这些资源文件。
25 |
26 | `grunt` (重新构建所有内容并运行测试用例)
27 | 编译并压缩 CSS 和 JavaScript 文件、构建文档站点、对文档做 HTML5 校验、重新生成定制工具所需的资源文件等,都需要 Jekyll 工具。这些只有在你对 Bootstrap 深度研究时才有用。
28 |
29 | ## 除错
30 | 如果你在安装依赖包或者运行 Grunt 命令时遇到了问题,请首先删除 npm 自动生成的 `/node_modules/` 目录,然后,再次运行 `npm install `命令。
--------------------------------------------------------------------------------
/getting-started/license-faqs.md:
--------------------------------------------------------------------------------
1 | # 许可证 FAQ
2 |
3 | Bootstrap 遵守 MIT 许可证进行发布,2015 Twitter 版权所有。归结为以下几点:
4 |
5 | 必须遵守:
6 |
7 | Include the license and copyright notice in your works
8 | 赋予你的权力:
9 |
10 | Freely download and use Bootstrap, in whole or in part, for personal, private, company internal, or commercial purposes
11 | Use Bootstrap in packages or distributions that you create
12 | Modify the source code
13 | Grant a sublicense to modify and distribute Bootstrap to third parties not included in the license
14 | 禁止以下行为:
15 |
16 | Hold the authors and license owners liable for damages as Bootstrap is provided without warranty
17 | Hold the creators or copyright holders of Bootstrap liable
18 | Redistribute any piece of Bootstrap without proper attribution
19 | Use any marks owned by Twitter in any way that might state or imply that Twitter endorses your distribution
20 | Use any marks owned by Twitter in any way that might state or imply that you created the Twitter software in question
21 | It does not require you to:
22 |
23 | Include the source of Bootstrap itself, or of any modifications you may have made to it, in any redistribution you may assemble that includes it
24 | Submit changes that you make to Bootstrap back to the Bootstrap project (though such feedback is encouraged)
25 | Bootstrap 完整的许可证包含在 项目仓库中,请参考。
26 |
27 |
--------------------------------------------------------------------------------
/getting-started/basic-template.md:
--------------------------------------------------------------------------------
1 | # 基本模板
2 |
3 | 使用以下给出的这份超级简单的 HTML 模版,或者修改这些实例。我们强烈建议你对这些实例按照自己的需求进行修改,而不要简单的复制、粘贴。
4 |
5 | 拷贝并粘贴下面给出的 HTML 代码,这就是一个最简单的 Bootstrap 页面了。
6 |
7 | ```
8 |
9 |
10 |
11 |
12 |
13 |
14 | Bootstrap 101 Template
15 |
16 |
17 |
18 |
19 |
20 |
21 |
25 |
26 |
27 | 你好,世界!
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | ```
--------------------------------------------------------------------------------
/getting-started/third-party-support.md:
--------------------------------------------------------------------------------
1 | # 对第三方组件的支持
2 |
3 | 虽然我们并不官方支持任何第三方插件,我们还是提供一些建议,帮你避免可能在你的项目中会出现的问题。
4 |
5 | ## box-sizing 属性
6 | 某些第三方软件,包括 Google 地图和 Google 定制搜索引擎都会由于 `* { box-sizing: border-box; }` 的设置而产生冲突,这一设置使 `padding `不影响页面元素最终宽度的计算。更多信息请参考 盒模型与尺寸计算 - CSS Tricks。
7 |
8 | 根据不同情况,你可能需要根据情况覆盖(第1种选择)或为所有区域设置(第2种选择)。
9 |
10 | ```
11 | /* Box-sizing resets
12 | *
13 | * 为了避免 Bootstrap 设置的全局盒模型所带来的影响,可以重置单个页面元素或覆盖整个区域的盒模型。
14 | * 你有两种选择:覆盖单个页面元素或重置整个区域。它们都可以通过纯 CSS 或 LESS 代码的形式实现。
15 | */
16 |
17 | /* Option 1A: 通过 CSS 代码覆盖单个页面元素的盒模型 */
18 | .element {
19 | -webkit-box-sizing: content-box;
20 | -moz-box-sizing: content-box;
21 | box-sizing: content-box;
22 | }
23 |
24 | /* Option 1B: 通过使用 Bootstrap 提供的 LESS mixin 覆盖单个页面元素的盒模型 */
25 | .element {
26 | .box-sizing(content-box);
27 | }
28 |
29 | /* Option 2A: 通过 CSS 代码重置整个区域 */
30 | .reset-box-sizing,
31 | .reset-box-sizing *,
32 | .reset-box-sizing *:before,
33 | .reset-box-sizing *:after {
34 | -webkit-box-sizing: content-box;
35 | -moz-box-sizing: content-box;
36 | box-sizing: content-box;
37 | }
38 |
39 | /* Option 2B: 通过使用自定义的 LESS mixin 重置整个区域 */
40 | .reset-box-sizing {
41 | &,
42 | *,
43 | *:before,
44 | *:after {
45 | .box-sizing(content-box);
46 | }
47 | }
48 | .element {
49 | .reset-box-sizing();
50 | }
51 | ```
--------------------------------------------------------------------------------
/getting-started/accessibility.md:
--------------------------------------------------------------------------------
1 | # 可访问性
2 |
3 | Bootstrap 遵循统一的 web 标准,另外,通过做一些少量的修改,还可以让使用 辅助设备(AT - ASSISTIVE TECHNOLOGY)上网的人群访问你的站点。
4 |
5 | ##跳过导航区
6 | 如果你的导航部分包含很多链接,并且在 DOM 结构上也是排在主内容之前,那么,建议在导航前面添加一个 Skip to main content(直接进入主内容区) 的链接,(这里解释了这样做的原因)。 Using the .sr-only class will visually hide the skip link, and the .sr-only-focusable class will ensure that the link becomes visible once focused (for sighted keyboard users).
7 |
8 | ```
9 |
10 | Skip to main content
11 | ...
12 |
13 |
14 |
15 |
16 | ```
17 |
18 | ## 标题嵌套
19 | 当标题嵌套时 (` `- ``),你的文档的主标题应该是 `` 标签。随后的标题逻辑上就应该使用 `` - ` `,这样,屏幕阅读器就可以构造出页面的内容列表了。
20 |
21 | 更多信息请参考: HTML CodeSniffer and Penn State's AccessAbility.
22 |
23 | ## Color contrast
24 | Currently, some of the default color combinations available in Bootstrap (such as the various styled button classes, some of the code highlighting colors used for basic code blocks, the `.bg-primary` contextual background helper class, and the default link color when used on a white background) have a low contrast ratio (below the recommended ratio of 4.5:1). This can cause problems to users with low vision or who are color blind. These default colors may need to be modified to increase their contrast and legibility.
25 |
26 | 扩展阅读
27 | "HTML Codesniffer" bookmarklet for identifying accessibility issues
28 | Chrome's Accessibility Developer Tools extension
29 | Colour Contrast Analyser
30 | The A11Y Project
31 | MDN accessibility documentation
32 |
--------------------------------------------------------------------------------
/getting-started/what-included.md:
--------------------------------------------------------------------------------
1 | # 包含的内容
2 |
3 | Bootstrap 提供了两种形式的压缩包,在下载下来的压缩包内可以看到以下目录和文件,这些文件按照类别放到了不同的目录内,并且提供了压缩与未压缩两种版本。
4 |
5 | `Bootstrap 插件全部依赖 jQuery`
6 | 请注意,**Bootstrap 的所有 JavaScript 插件都依赖 jQuery**,因此 jQuery 必须在 Bootstrap 之前引入,就像在基本模版中所展示的一样。在 `bower.json `文件中 列出了 Bootstrap 所支持的 jQuery 版本。
7 | ##预编译版
8 | 下载压缩包之后,将其解压缩到任意目录即可看到以下(压缩版的)目录结构:
9 |
10 | ```
11 | bootstrap/
12 | ├── css/
13 | │ ├── bootstrap.css
14 | │ ├── bootstrap.css.map
15 | │ ├── bootstrap.min.css
16 | │ ├── bootstrap-theme.css
17 | │ ├── bootstrap-theme.css.map
18 | │ └── bootstrap-theme.min.css
19 | ├── js/
20 | │ ├── bootstrap.js
21 | │ └── bootstrap.min.js
22 | └── fonts/
23 | ├── glyphicons-halflings-regular.eot
24 | ├── glyphicons-halflings-regular.svg
25 | ├── glyphicons-halflings-regular.ttf
26 | ├── glyphicons-halflings-regular.woff
27 | └── glyphicons-halflings-regular.woff2
28 | ```
29 | 上面展示的就是 Bootstrap 的基本文件结构:预编译文件可以直接使用到任何 web 项目中。我们提供了编译好的 CSS 和 JS (`bootstrap.*`) 文件,还有经过压缩的 CSS 和 JS (`bootstrap.min.*`) 文件。同时还提供了 CSS 源码映射表 (`bootstrap.*.map`) ,可以在某些浏览器的开发工具中使用。同时还包含了来自 Glyphicons 的图标字体,在附带的 Bootstrap 主题中使用到了这些图标。
30 |
31 | ##Bootstrap 源码
32 | Bootstrap 源码包含了预先编译的 CSS、JavaScript 和图标字体文件,并且还有 LESS、JavaScript 和文档的源码。具体来说,主要文件组织结构如下:
33 |
34 | ```
35 | bootstrap/
36 | ├── less/
37 | ├── js/
38 | ├── fonts/
39 | ├── dist/
40 | │ ├── css/
41 | │ ├── js/
42 | │ └── fonts/
43 | └── docs/
44 | └── examples/
45 | ```
46 | `less/`、`js/` 和 `fonts/` 目录分别包含了 CSS、JS 和字体图标的源码。`dist/` 目录包含了上面所说的预编译 Bootstrap 包内的所有文件。`docs/` 包含了所有文档的源码文件,`examples/` 目录是 Bootstrap 官方提供的实例工程。除了这些,其他文件还包含 Bootstrap 安装包的定义文件、许可证文件和编译脚本等。
--------------------------------------------------------------------------------
/css/overview.md:
--------------------------------------------------------------------------------
1 | # 概览
2 |
3 | 深入了解 Bootstrap 底层结构的关键部分,包括我们让 web 开发变得更好、更快、更强壮的最佳实践。
4 |
5 | ## HTML5 文档类型
6 | Bootstrap 使用到的某些 HTML 元素和 CSS 属性需要将页面设置为 HTML5 文档类型。在你项目中的每个页面都要参照下面的格式进行设置。
7 |
8 | ```
9 |
10 |
11 | ...
12 |
13 | ```
14 | ## 移动设备优先
15 | 在 Bootstrap 2 中,我们对框架中的某些关键部分增加了对移动设备友好的样式。而在 Bootstrap 3 中,我们重写了整个框架,使其一开始就是对移动设备友好的。这次不是简单的增加一些可选的针对移动设备的样式,而是直接融合进了框架的内核中。也就是说,**Bootstrap 是移动设备优先的**。针对移动设备的样式融合进了框架的每个角落,而不是增加一个额外的文件。
16 |
17 | 为了确保适当的绘制和触屏缩放,需要在 `` 之中**添加 viewport 元数据标签**。
18 |
19 | ```
20 |
21 | ```
22 | 在移动设备浏览器上,通过为视口(viewport)设置 meta 属性为 `user-scalable=no` 可以禁用其缩放(zooming)功能。这样禁用缩放功能后,用户只能滚动屏幕,就能让你的网站看上去更像原生应用的感觉。注意,这种方式我们并不推荐所有网站使用,还是要看你自己的情况而定!
23 |
24 | ```
25 |
26 | ```
27 | ## 排版与链接
28 | Bootstrap 排版、链接样式设置了基本的全局样式。分别是:
29 |
30 | 为 `body` 元素设置 `background-color: #fff`;
31 | 使用 `@font-family-base`、`@font-size-base` 和 `@line-height-base` a变量作为排版的基本参数
32 | 为所有链接设置了基本颜色 `@link-color` ,并且当链接处于 `:hover` 状态时才添加下划线
33 | 这些样式都能在 `scaffolding.less` 文件中找到对应的源码。
34 |
35 | ## Normalize.css
36 | 为了增强跨浏览器表现的一致性,我们使用了 Normalize.css,这是由 Nicolas Gallagher 和 Jonathan Neal 维护的一个CSS 重置样式库。
37 |
38 | 布局容器
39 | Bootstrap 需要为页面内容和栅格系统包裹一个 `.container` 容器。我们提供了两个作此用处的类。注意,由于 `padding` 等属性的原因,这两种 容器类不能互相嵌套。
40 |
41 | `.container` 类用于固定宽度并支持响应式布局的容器。
42 |
43 | ```
44 |
45 | ...
46 |
47 | ```
48 | `.container-fluid` 类用于 100% 宽度,占据全部视口(viewport)的容器。
49 |
50 | ```
51 |
52 | ...
53 |
54 | ```
55 |
--------------------------------------------------------------------------------
/javascript/overview.md:
--------------------------------------------------------------------------------
1 | # 概览 - Overview
2 |
3 | ## 单个还是全部引入
4 |
5 | JavaScript 插件可以单个引入(使用 Bootstrap 提供的单个 `*.js` 文件),或者一次性全部引入(使用 `bootstrap.js` 或压缩版的 `bootstrap.min.js`)。
6 |
7 | >
8 | **建议使用压缩版的 JavaScript 文件**
9 | `bootstrap.js` 和 `bootstrap.min.js` 都包含了所有插件,你在使用时,只需选择一个引入页面就可以了。
10 |
11 | >
12 | **插件之间的依赖关系**
13 | 某些插件和 CSS 组件依赖于其它插件。如果你是单个引入每个插件的,请确保在文档中检查插件之间的依赖关系。注意,所有插件都依赖 jQuery (也就是说,jQuery必须在所有插件之前引入页面)。 `bower.json` 文件中列出了 Bootstrap 所支持的 jQuery 版本。
14 |
15 | ## data 属性
16 |
17 | 你可以仅仅通过 data 属性 API 就能使用所有的 Bootstrap 插件,无需写一行 JavaScript 代码。这是 Bootstrap 中的一等 API,也应该是你的首选方式。
18 |
19 | 话又说回来,在某些情况下可能需要将此功能关闭。因此,我们还提供了关闭 data 属性 API 的方法,即解除以 `data-api` 为命名空间并绑定在文档上的事件。就像下面这样:
20 |
21 | ```
22 | $(document).off('.data-api')
23 | ```
24 |
25 | 另外,如果是针对某个特定的插件,只需在 `data-api` 前面添加那个插件的名称作为命名空间,如下:
26 |
27 | ```
28 | $(document).off('.alert.data-api')
29 | ```
30 |
31 | >
32 | **Only one plugin per element via data attributes**
33 | Don't use data attributes from multiple plugins on the same element. For example, a button cannot both have a tooltip and toggle a modal. To accomplish this, use a wrapping element.
34 |
35 | ## 编程方式的 API
36 |
37 | 我们为所有 Bootstrap 插件提供了纯 JavaScript 方式的 API。所有公开的 API 都是支持单独或链式调用方式,并且返回其所操作的元素集合(注:和jQuery的调用形式一致)。
38 |
39 | ```
40 | $('.btn.danger').button('toggle').addClass('fat')
41 | ```
42 |
43 | 所有方法都可以接受一个可选的 option 对象作为参数,或者一个代表特定方法的字符串,或者什么也不提供(在这种情况下,插件将会以默认值初始化):
44 |
45 | ```
46 | $('#myModal').modal() // 以默认值初始化
47 | $('#myModal').modal({ keyboard: false }) // initialized with no keyboard
48 | $('#myModal').modal('show') // 初始化后立即调用 show 方法
49 | ```
50 |
51 | 每个插件还通过 `Constructor` 属性暴露了其原始的构造函数:`$.fn.popover.Constructor`。如果你想获取某个插件的实例,可以直接通过页面元素获取:`$('[rel="popover"]').data('popover')`。
52 |
53 | 默认设置
54 |
55 | 每个插件都可以通过修改其自身的 `Constructor.DEFAULTS` 对象从而改变插件的默认设置:
56 |
57 | ```
58 | $.fn.modal.Constructor.DEFAULTS.keyboard = false // 将模态框插件的 `keyboard` 默认选参数置为 false
59 | ```
60 |
61 | ## 避免命名空间冲突
62 |
63 | 某些时候可能需要将 Bootstrap 插件与其他 UI 框架共同使用。在这种情况下,命名空间冲突随时可能发生。如果不幸发生了这种情况,你可以通过调用插件的 `.noConflict` 方法恢复其原始值。
64 |
65 | ```
66 | var bootstrapButton = $.fn.button.noConflict() // return $.fn.button to previously assigned value
67 | $.fn.bootstrapBtn = bootstrapButton // give $().bootstrapBtn the Bootstrap functionality
68 | ```
69 |
70 | ## 事件
71 |
72 | Bootstrap 为大部分插件所具有的动作提供了自定义事件。一般来说,这些事件都有不定式和过去式两种动词的命名形式,例如,不定式形式的动词(例如 `show`)表示其在事件开始时被触发;而过去式动词(例如 `shown`)表示在动作执行完毕之后被触发。
73 |
74 | 从 3.0.0 版本开始,所有 Bootstrap 事件的名称都采用命名空间方式。
75 |
76 | 所有以不定式形式的动词命名的事件都提供了 `preventDefault` 功能。这就赋予你在动作开始执行前将其停止的能力。
77 |
78 | ```
79 | $('#myModal').on('show.bs.modal', function (e) {
80 | if (!data) return e.preventDefault() // 阻止模态框的展示
81 | })
82 | ```
83 |
84 | ## Version numbers
85 |
86 | The version of each of Bootstrap's jQuery plugins can be accessed via the `VERSION` property of the plugin's constructor. For example, for the tooltip plugin:
87 |
88 | ```
89 | $.fn.tooltip.Constructor.VERSION // => "3.3.4"
90 | ```
91 |
92 | ## 未对禁用 JavaScript 的浏览器提供补救措施
93 |
94 | Bootstrap 插件未对禁用 JavaScript 的浏览器提供补救措施。如果你对这种情况下的用户体验很关心的话,请添加 `` 标签向你的用户进行解释(并告诉他们如何启用 JavaScript),或者按照你自己的方式提供补救措施。
95 |
96 |
97 | ## 第三方工具库
98 |
99 | Bootstrap 官方不提供对第三方 JavaScript 工具库的支持,例如 Prototype 或 jQuery UI。除了 `.noConflict` 和为事件名称添加命名空间,还可能会有兼容性方面的问题,这就需要你自己来处理了。
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/TOC.md:
--------------------------------------------------------------------------------
1 | - 起步-Getting started
2 | - [下载 - Download](getting-started/download.md)
3 | - [包含的内容 - What included](getting-started/what-included.md)
4 | - [编译 CSS 和 JavaScript 文件 - Compiling CSS and JavaScript](getting-started/compiling-css-and-javascript.md)
5 | - [基本模板 - Basic template](getting-started/basic-template.md)
6 | - [实例精选 - Examples](getting-started/examples.md)
7 | - [工具 - Tools](getting-started/tools.md)
8 | - [社区 - Community](getting-started/community.md)
9 | - [禁止响应式布局 - Disabling responsiveness](getting-started/disabling-responsiveness.md)
10 | - [从 2.x 版本升级到 3.0 版本 - Migrating from v2.x to v3.x](getting-started/migrating-from-v2.x-to-v3.x.md)
11 | - [对浏览器和设备的支持情况 - Browser and device support](getting-started/browser-and-device-support.md)
12 | - [对第三方组件的支持 - Third party support](getting-started/third-party-support.md)
13 | - [可访问性 - Accessibility](getting-started/accessibility.md)
14 | - [许可证 FAQ - License FAQs](getting-started/license-faqs.md)
15 | - [文档翻译 - Translations](getting-started/translations.md)
16 | - CSS
17 | - [概览 - Overview](css/overview.md)
18 | - [栅格系统 - Grid system](css/grid-system.md)
19 | - [排版 - Typography](css/typography.md)
20 | - [代码 - Code](css/code.md)
21 | - [表格 - Tables](css/tables.md)
22 | - [表单 - Forms](css/forms.md)
23 | - [按钮 - Buttons](css/buttons.md)
24 | - [图片 - Images](css/Images.md)
25 | - [辅助类 - Helper classes](css/helper-classes.md)
26 | - [响应式工具 - Responsive utilities](css/responsive-utilities.md)
27 | - [使用 Less - Using Less](css/using-less.md)
28 | - [使用 Sass - Using Sass](css/using-sass.md)
29 | - 组件-Components
30 | - [Glyphicons 字体图标 - Glyphicons](components/glyphicons.md)
31 | - [下拉菜单 - Dropdowns](components/dropdowns.md)
32 | - [按钮组 - Button groups](components/button-groups.md)
33 | - [按钮式下拉菜单 - Button dropdowns](components/button-dropdowns.md)
34 | - [输入框组 - Input groups](components/input-groups.md)
35 | - [导航 - Navs](components/navs.md)
36 | - [导航条 - Navbar](components/navbar.md)
37 | - [路径导航 - Breadcrumbs](components/breadcrumbs.md)
38 | - [分页 - Pagination](components/pagination.md)
39 | - [标签 - Labels](components/labels.md)
40 | - [徽章 - Badges](components/badges.md)
41 | - [巨幕 - Jumbotron](components/jumbotron.md)
42 | - [页头 - Page header](components/page-header.md)
43 | - [缩略图 - Thumbnails](components/thumbnails.md)
44 | - [警告框 - Alerts](components/alerts.md)
45 | - [进度条 - Progress bars](components/progress-bars.md)
46 | - [媒体对象 - Media object](components/media-object.md)
47 | - [列表组 - List group](components/list-group.md)
48 | - [面板 - Panels](components/panels.md)
49 | - [具有响应式特性的嵌入内容 - Responsive embed](components/responsive-embed.md)
50 | - [Well - Wells](components/wells.md)
51 | - JavaScript
52 | - [概览 - Overview](javascript/overview.md)
53 | - [过渡效果 - Transitions](javascript/transitions.md)
54 | - [模态框 - Modal](javascript/modal.md)
55 | - [下拉菜单 - Dropdowns](javascript/dropdowns.md)
56 | - [滚动监听 - Scrollspy](javascript/scrollspy.md)
57 | - [标签页 - Tab](javascript/tab.md)
58 | - [工具提示 - Tooltips](javascript/tooltips.md)
59 | - [弹出框 - Popovers](javascript/popovers.md)
60 | - [警告框 - Alert](javascript/alert.md)
61 | - [按钮 - Button](javascript/button.md)
62 | - [Collapse - Collapse](javascript/collapse.md)
63 | - [Carousel - Carousel](javascript/carousel.md)
64 | - [Affix - Affix](javascript/affix.md)
65 | - 定制-Customize
66 | - [入口 - Import](customize/import.md)
67 | - [较小的组件 - Less components](customize/less-components.md)
68 | - [jQuery插件 - jQuery plugins](customize/jquery-plugins.md)
69 | - [较小的变量 - Less variables](customize/less-variables.md)
70 | - [下载 - Download](customize/download.md)
71 |
72 |
--------------------------------------------------------------------------------
/css/typography.md:
--------------------------------------------------------------------------------
1 | # 排版
2 |
3 | ## 标题
4 | HTML 中的所有标题标签,`` 到 `` 均可使用。另外,还提供了 `.h1` 到 `.h6` 类,为的是给内联(inline)属性的文本赋予标题的样式。
5 |
6 |
7 |
8 | ```
9 | h1. Bootstrap heading
10 | h2. Bootstrap heading
11 | h3. Bootstrap heading
12 | h4. Bootstrap heading
13 | h5. Bootstrap heading
14 | h6. Bootstrap heading
15 | ```
16 | 在标题内还可以包含 `` 标签或赋予 `.small` 类的元素,可以用来标记副标题。
17 |
18 |
19 |
20 | ```
21 | h1. Bootstrap heading Secondary text
22 | h2. Bootstrap heading Secondary text
23 | h3. Bootstrap heading Secondary text
24 | h4. Bootstrap heading Secondary text
25 | h5. Bootstrap heading Secondary text
26 | h6. Bootstrap heading Secondary text
27 | ```
28 | ## 页面主体
29 | Bootstrap 将全局 `font-size` 设置为 14px,`line-height` 设置为 1.428。这些属性直接赋予 `` 元素和所有段落元素。另外,` ` (段落)元素还被设置了等于 1/2 行高(即 10px)的底部外边距(margin)。
30 |
31 |
32 |
33 | ```
34 |
...
35 | ```
36 |
37 | ###中心内容
38 | 通过添加 `.lead` 类可以让段落突出显示。
39 |
40 |
41 |
42 |
43 | ```
44 | ...
45 | ```
46 | ###使用 Less 工具构建
47 | **variables.less** 文件中定义的两个 Less 变量决定了排版尺寸:`@font-size-base` 和 @line-height-base。第一个变量定义了全局 font-size 基准,第二个变量是 line-height 基准。我们使用这些变量和一些简单的公式计算出其它所有页面元素的 margin、 padding 和 line-height。自定义这些变量即可改变 Bootstrap 的默认样式。
48 |
49 | ##内联文本元素
50 | ###Marked text
51 | For highlighting a run of text due to its relevance in another context, use the `` tag.
52 |
53 |
54 |
55 |
56 | ```
57 | You can use the mark tag to highlight text.
58 | ```
59 | ###被删除的文本
60 | 对于被删除的文本使用 `` 标签。
61 |
62 |
63 |
64 |
65 | ```
66 | This line of text is meant to be treated as deleted text.
67 | ```
68 | ###无用文本
69 | 对于没用的文本使用 `` 标签。
70 |
71 |
72 |
73 |
74 | ```
75 | This line of text is meant to be treated as no longer accurate.
76 | ```
77 | ###插入文本
78 | 额外插入的文本使用 `` 标签。
79 |
80 |
81 |
82 |
83 | ```
84 | This line of text is meant to be treated as an addition to the document.
85 | ```
86 | ###带下划线的文本
87 | 为文本添加下划线,使用 `` 标签。
88 |
89 |
90 |
91 |
92 | ```
93 | This line of text will render as underlined
94 | ```
95 | 利用 HTML 自带的表示强调意味的标签来为文本增添少量样式。
96 |
97 | ###小号文本
98 | 对于不需要强调的inline或block类型的文本,使用 `` 标签包裹,其内的文本将被设置为父容器字体大小的 85%。标题元素中嵌套的 `` 元素被设置不同的 `font-size` 。
99 |
100 | 你还可以为行内元素赋予 `.small` 类以代替任何 `` 元素。
101 |
102 |
103 |
104 |
105 | ```
106 | This line of text is meant to be treated as fine print.
107 | ```
108 | ###着重
109 | 通过增加 font-weight 值强调一段文本。
110 |
111 |
112 |
113 | ```
114 | rendered as bold text
115 | ```
116 | ###斜体
117 | 用斜体强调一段文本。
118 |
119 |
120 |
121 | ```
122 | rendered as italicized text
123 | ```
124 |
125 | **Alternate elements**
126 |
127 | 在 HTML5 中可以放心使用 `` 和 `` 标签。`` 用于高亮单词或短语,不带有任何着重的意味;而 `` 标签主要用于发言、技术词汇等。
128 | ##对齐
129 | 通过文本对齐类,可以简单方便的将文字重新对齐。
130 |
131 |
132 |
133 |
134 | ```
135 | Left aligned text.
136 | Center aligned text.
137 | Right aligned text.
138 | Justified text.
139 | No wrap text.
140 | ```
141 | ##改变大小写
142 | 通过这几个类可以改变文本的大小写。
143 |
144 |
145 |
146 |
147 | ```
148 | Lowercased text.
149 | Uppercased text.
150 | Capitalized text.
151 | ```
152 | ##缩略语
153 | 当鼠标悬停在缩写和缩写词上时就会显示完整内容,Bootstrap 实现了对 HTML 的 `` 元素的增强样式。缩略语元素带有 `title` 属性,外观表现为带有较浅的虚线框,鼠标移至上面时会变成带有“问号”的指针。如想看完整的内容可把鼠标悬停在缩略语上(对使用辅助技术的用户也可见), 但需要包含 title 属性。
154 |
155 | ###基本缩略语
156 |
157 |
158 |
159 |
160 | ```
161 | attr
162 | ```
163 | ###首字母缩略语
164 | 为缩略语添加 `.initialism` 类,可以让 font-size 变得稍微小些。
165 |
166 |
167 |
168 |
169 | ```
170 | HTML
171 | ```
172 | ##地址
173 | 让联系信息以最接近日常使用的格式呈现。在每行结尾添加 ` ` 可以保留需要的样式。
174 |
175 |
176 |
177 |
178 | ```
179 |
180 | Twitter, Inc.
181 | 795 Folsom Ave, Suite 600
182 | San Francisco, CA 94107
183 | P: (123) 456-7890
184 |
185 |
186 |
187 | Full Name
188 | first.last@example.com
189 |
190 | ```
191 | ##引用
192 | 在你的文档中引用其他来源的内容。
193 |
194 | ###默认样式的引用
195 | 将任何 HTML 元素包裹在 `` 中即可表现为引用样式。对于直接引用,我们建议用 `` 标签。
196 |
197 |
198 |
199 |
200 | ```
201 |
202 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
203 |
204 | ```
205 | ###Blockquote options
206 | Style and content changes for simple variations on a standard ``.
207 |
208 | ####Naming a source
209 |
210 | Add a `` for identifying the source. Wrap the name of the source work in ``.
211 |
212 |
213 |
214 |
215 |
216 | ```
217 |
218 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
219 | Someone famous in Source Title
220 |
221 |
222 | ```
223 | ####Alternate displays
224 |
225 |
226 |
227 |
228 | ```
229 |
230 | ...
231 |
232 | ```
233 | ##列表
234 | ###无序列表
235 | ####排列顺序无关紧要的一列元素。
236 |
237 |
238 |
239 |
240 | ```
241 |
244 | ```
245 | ###有序列表
246 | ####顺序至关重要的一组元素。
247 |
248 |
249 |
250 |
251 |
252 | ```
253 |
254 | ...
255 |
256 | ```
257 | ###无样式列表
258 | 移除了默认的 `list-style` 样式和左侧外边距的一组元素(只针对直接子元素)。**这是针对直接子元素的**,也就是说,你需要对所有嵌套的列表都添加这个类才能具有同样的样式。
259 |
260 |
261 |
262 |
263 | ```
264 |
267 | ```
268 | ###内联列表
269 | 通过设置 `display: inline-block;` 并添加少量的内补(padding),将所有元素放置于同一行。
270 |
271 |
272 |
273 |
274 | ```
275 |
278 | ```
279 | ###描述
280 | 带有描述的短语列表。
281 |
282 |
283 |
284 |
285 | ```
286 |
287 | ...
288 | ...
289 |
290 | ```
291 | ####水平排列的描述
292 |
293 | `.dl-horizontal` 可以让 `` 内的短语及其描述排在一行。开始是像 `` 的默认样式堆叠在一起,随着导航条逐渐展开而排列在一行。
294 |
295 |
296 |
297 |
298 |
299 | ```
300 |
301 | ...
302 | ...
303 |
304 | ```
305 | 自动截断
306 | 通过 `text-overflow` 属性,水平排列的描述列表将会截断左侧太长的短语。在较窄的视口(viewport)内,列表将变为默认堆叠排列的布局方式。
307 |
--------------------------------------------------------------------------------
/getting-started/browser-and-device-support.md:
--------------------------------------------------------------------------------
1 | # 浏览器和设备的支持情况
2 |
3 | Bootstrap 的目标是在最新的桌面和移动浏览器上有最佳的表现,也就是说,在较老旧的浏览器上可能会导致某些组件表现出的样式有些不同,但是功能是完整的。
4 |
5 | ## 被支持的浏览器
6 | 特别注意,我们坚决支持这些浏览器的**最新版本**。在 Windows 平台,我们支持 **Internet Explorer 8-11**。请看下面列出的详细信息。
7 |
8 | |Chrome |Firefox |Internet Explorer |Opera|Safari
9 | |--------|--------|----------|------------|------
10 | |Android |支持 | 支持 |N/A | 不支持 | N/A
11 |
12 |
13 |
14 | iOS 支持 N/A 不支持 支持
15 | Mac OS X 支持 支持 支持 支持
16 | Windows 支持 支持 支持 支持 不支持
17 | Bootstrap 在 Chromium 和 Linux 版 Chrome、Linux 版 Firefox 和 Internet Explorer 7 上的表现也是很不错的,虽然我们不对其进行官方支持。
18 |
19 | | Tables | Are | Cool |
20 | | ------------- |:-------------:| -----:|
21 | | col 3 is | right-aligned | $1600 |
22 | | col 2 is | centered | $12 |
23 | | zebra stripes | are neat | $1 |
24 |
25 | 浏览器 bug 列表中列出了影响 Bootstrap 正常功能的浏览器 bug。
26 |
27 | ## Internet Explorer 8 和 9
28 | Internet Explorer 8 和 9 是被支持的,然而,你要知道,很多 CSS3 属性和 HTML5 元素 -- 例如,圆角矩形和投影 -- 是肯定不被支持的。另外, **Internet Explorer 8 需要 Respond.js 配合才能实现对媒体查询(media query)的支持。**
29 |
30 | Feature Internet Explorer 8 Internet Explorer 9
31 | border-radius 不支持 支持
32 | box-shadow 不支持 支持
33 | transform 不支持 支持, with -ms prefix
34 | transition 不支持
35 | placeholder 不支持
36 | 请参考 Can I use... 以获取详细的 CSS3 和 HTML5 特性在各个浏览器上的支持情况。
37 |
38 | ## Internet Explorer 8 与 Respond.js
39 | 在开发环境和生产(线上)环境需要支持 Internet Explorer 8 时,请务必注意下面给出的警告。
40 |
41 | Respond.js 与 跨域(cross-domain) CSS 的问题
42 |
43 | 如果 Respond.js 和 CSS 文件被放在不同的域名或子域名下面(例如,使用CDN)时需要一些额外的设置。请参考 Respond.js 文档 获取详细信息。
44 |
45 | Respond.js 与 `file://` 协议
46 |
47 | 由于浏览器的安全机制,Respond.js 不能在通过 `file://` 协议(打开本地HTML文件所用的协议)访问的页面上发挥正常的功能。如果需要测试 IE8 下面的响应式特性,务必通过 http 协议访问页面(例如搭建 apache、nginx 等)。请参考 Respond.js 文档获取更多信息。
48 |
49 | Respond.js 与 `@import` 指令
50 |
51 | Respond.js 不支持通过 `@import` 指令所引入的 CSS 文件。例如,Drupal 一般被配置为通过 `@import` 指令引入CSS文件,Respond.js 对其将无法起到作用。请参考 Respond.js 文档获取更多信息。
52 |
53 | ## Internet Explorer 8 与 box-sizing 属性
54 | 当 box-sizing: border-box; 与 min-width、max-width、min-height 或 max-height 一同使用时,IE8 不能完全支持 box-sizing 属相。由于此原因,从 Bootstrap v3.0.1 版本开始,我们不再为 .container 赋予 max-width 属性。
55 |
56 | ## Internet Explorer 8 与 @font-face
57 | 当 `@font-face` 与 `:before` 在 IE8 下共同使用时会出现问题。由于 Bootstrap 对 Glyphicons 的样式设置使用了这一组合方式,如果某个页面被浏览器缓存了,并且此页面不是通过点击“刷新”按钮或通过 iframe 加载的,那么就会导致字体文件尚未加载的情况下就开始绘制此页面。当鼠标滑过页面(body)时,页面上的某些图标就会显现,鼠标滑过其他没有显现的图标时,这些图标就能显示出来了。请参考 issue #13863 了解详细信息。
58 |
59 | ## IE 兼容模式
60 | Bootstrap 不支持 IE 古老的兼容模式。为了让 IE 浏览器运行最新的渲染模式下,建议将此 ` `标签加入到你的页面中:
61 |
62 | ```
63 |
64 | ```
65 | 按 `F12 `键打开 IE 的调试工具,就可以看到 IE 当前的渲染模式是什么。
66 |
67 | 此 meta 标签被包含在了所有 Bootstrap 文档和实例页面中,为的就是在每个被支持的 IE 版本中拥有最好的绘制效果。
68 |
69 | 请参考 这个发表在 StackOverflow 上的问题。
70 |
71 | 国产浏览器高速模式
72 | 国内浏览器厂商一般都支持兼容模式(即 IE 内核)和高速模式(即 webkit 内核),不幸的是,所有国产浏览器都是默认使用兼容模式,这就造成由于低版本 IE (IE8 及以下)内核让基于 Bootstrap 构建的网站展现效果很糟糕的情况。幸运的是,国内浏览器厂商逐渐意识到了这一点,某些厂商已经开始有所作为了!
73 |
74 | 将下面的 ` ` 标签加入到页面中,可以让部分国产浏览器默认采用高速模式渲染页面:
75 |
76 | ```
77 |
78 | ```
79 | 目前只有360浏览器支持此` `标签。希望更多国内浏览器尽快采取行动、尽快进入高速时代!
80 |
81 | ## Windows 8 中的 Internet Explorer 10 和 Windows Phone 8
82 | Internet Explorer 10 并没有对 **屏幕的宽度 和 视口(viewport)的宽度** 进行区分,这就导致 Bootstrap 中的媒体查询并不能很好的发挥作用。为了解决这个问题,你可以引入下面列出的这段 CSS 代码暂时修复此问题:
83 |
84 | ```
85 | @-ms-viewport { width: device-width; }
86 | ```
87 | 然而,这样做并不能对 Windows Phone 8 Update 3 (a.k.a. GDR3) 版本之前的设备起作用,由于这样做将导致 Windows Phone 8 设备按照桌面浏览器的方式呈现页面,而不是较窄的“手机”呈现方式,为了解决这个问题,还需要加入以下 **CSS 和 JavaScript** 代码来化解此问题。
88 |
89 | ```
90 | @-webkit-viewport { width: device-width; }
91 | @-moz-viewport { width: device-width; }
92 | @-ms-viewport { width: device-width; }
93 | @-o-viewport { width: device-width; }
94 | @viewport { width: device-width; }
95 | ```
96 | ```
97 | if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
98 | var msViewportStyle = document.createElement('style')
99 | msViewportStyle.appendChild(
100 | document.createTextNode(
101 | '@-ms-viewport{width:auto!important}'
102 | )
103 | )
104 | document.querySelector('head').appendChild(msViewportStyle)
105 | }
106 | ```
107 | 请查看 Windows Phone 8 and Device-Width 以了解更多信息。
108 |
109 | 作为提醒,我们将上面的代码加入到了所有 Bootstrap 文档和实例页面中。
110 |
111 | ## Safari 对百分比数字凑整的问题
112 | OS X 上搭载的 v7.1 以前 Safari 和 iOS v8.0 上搭载的 Safari 浏览器的绘制引擎对于处理 `.col-*-1 `类所对应的很长的百分比小数存在 bug。也就是说,如果你在一行(row)之中定义了12个单独的列(.col-*-1),你就会看到这一行比其他行要短一些。除了升级 Safari/iOS 外,有以下几种方式来应对此问题:
113 |
114 | 为最后一列添加 `.pull-right` 类,将其暴力向右对齐
115 | 手动调整百分比数字,让其针对Safari表现更好(这比第一种方式更困难)
116 | ## 模态框、导航条和虚拟键盘
117 | ### Overflow and scrolling
118 |
119 | `` 元素在 iOS 和 Android 上对 `overflow: hidden` 的支持很有限。结果就是,在这两种设备上的浏览器中,当你滚动屏幕超过模态框的顶部或底部时,`` 中的内容将开始随着滚动。
120 |
121 | ### 虚拟键盘
122 |
123 | 还有,如果你正在使用 fixed 定位的导航条或在模态框上面使用输入框,还会遇到 iOS 在页面绘制上的 bug,当触发虚拟键盘之后,其不会更新 fixed 定位的元素的位置。这里有几种解决方案,包括将 fixed 定位转变为 `position: absolute` 定位,或者启动一个定时器手工修正组件的位置。这些没有加入 Bootstrap 中,因此,需要由你自己选择最好的解决方案并加入到你的应用中。
124 |
125 | ### 导航条上的下拉菜单
126 |
127 | 在 iOS 设备上,由于导航组件(nav)的复杂的 z-indexing 属性,.dropdown-backdrop 元素并未被使用。因此,为了关闭导航条上的下拉菜单,必须直接点击下拉菜单上的元素(或者任何其他能够触发 iOS 上 click 事件的元素)。
128 |
129 | ## 浏览器的缩放功能
130 | 页面缩放功能不可避免的会将某些组件搞得乱七八糟,不光是 Bootstrap ,整个互联网上的所有页面都是这样。针对具体问题,我们或许可以修复它(如果有必要的话,请先搜索一下你的问题,看看是否已有解决方案,然后在向我们提交 issue)。然而,我们更倾向于忽略这些问题,由于这些问题除了一些 hack 手段,一般没有直接的解决方案。
131 |
132 | ## 打印
133 | 即便是在某些很现代的浏览器中,打印页面功能也还是存在很多陷阱。
134 |
135 | 举个例子,从 Chrome v32 开始,打印一个支持媒体查询的页面时,不管如何设置留白,Chrome 总是使用一个远远小于实际页面尺寸的视口宽度的值作为页面宽度。这就导致被打印的页面总是被呈现为在超小屏幕(extra-small)上的效果(也就是激活了 Bootstrap 针对超小屏幕的栅格排布方式)。 参考 #12078 了解更多信息。 推荐解决方案:
136 |
137 | 让你的页面在超小(extra-small)屏幕上看起来不那么太差劲。
138 | 修改 `@screen-*` Less 变量的值,让你的页面总是大于 extra-small
139 | 添加额外的媒体查询代码,针对打印机修改栅格阈值。
140 | 另外,从Safari v8.0 开始,固定宽度的 `.container` 会导致 Safari 使用非常小的字号来打印页面。参见 #14868 了解跟多信息。下面这段 CSS 代码提供了一个临时解决方案:
141 |
142 | ```
143 | @media print {
144 | .container {
145 | width: auto;
146 | }
147 | }
148 | ```
149 | ## Android stock browser
150 | Out of the box, Android 4.1 (and even some newer releases apparently) ship with the Browser app as the default web browser of choice (as opposed to Chrome). Unfortunately, the Browser app has lots of bugs and inconsistencies with CSS in general.
151 |
152 | ## Select menus
153 |
154 | On ` `elements, the Android stock browser will not display the side controls if there is a `border-radius` and/or `border` applied. (See this StackOverflow question for details.) Use the snippet of code below to remove the offending CSS and render the` ` as an unstyled element on the Android stock browser. The user agent sniffing avoids interference with Chrome, Safari, and Mozilla browsers.
155 |
156 |
157 | ```
158 |
167 | ```
168 | 见 JS Bin 上的 demo。
169 |
170 | W3C 页面源码校验
171 | 为了在老旧的浏览器上尽量提供最好的展现,Bootstrap 针对浏览器使用了一些 CSS hack 手段,为的是针对特定浏览器版本弥补浏览器自身的 bug。这些 CSS hack 手段在 CSS 校验器那里会被认为是无效代码。还有一些地方,我们使用了某些未被完全标准化的 CSS 特性,纯粹是为了实现渐进式增强的思路。
172 |
173 | 上面提到的这些校验器报告的警告信息并不会对实际使用造成影响,因为非 hack 部分的 CSS 是完全合格的,hack 部分不会对非 hack 部分的功能产生影响,这就是我们故意无视这些校验器警告的原因。
174 |
175 | 同样,我们的 HTML 文档中也有一些针对 Firefox bug 的 hack 代码,在 HTML 校验时也会被警告。
--------------------------------------------------------------------------------
/css/grid-system.md:
--------------------------------------------------------------------------------
1 | # 栅格系统
2 |
3 | Bootstrap 提供了一套响应式、移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列。它包含了易于使用的预定义类,还有强大的mixin 用于生成更具语义的布局。
4 |
5 | ## 简介
6 | 栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局,你的内容就可以放入这些创建好的布局中。下面就介绍一下 Bootstrap 栅格系统的工作原理:
7 |
8 | “行(row)”必须包含在 `.container` (固定宽度)或 `.container-fluid` (100% 宽度)中,以便为其赋予合适的排列(aligment)和内补(padding)。
9 | 通过“行(row)”在水平方向创建一组“列(column)”。
10 | 你的内容应当放置于“列(column)”内,并且,只有“列(column)”可以作为行(row)”的直接子元素。
11 | 类似 `.row` 和 `.col-xs-4` 这种预定义的类,可以用来快速创建栅格布局。Bootstrap 源码中定义的 mixin 也可以用来创建语义化的布局。
12 | 通过为“列(column)”设置 `padding` 属性,从而创建列与列之间的间隔(gutter)。通过为 `.row` 元素设置负值 `margin` 从而抵消掉为 `.container` 元素设置的 `padding`,也就间接为“行(row)”所包含的“列(column)”抵消掉了`padding`。
13 | The negative margin is why the examples below are outdented. It's so that content within grid columns is lined up with non-grid content.
14 | Grid columns are created by specifying the number of twelve available columns you wish to span. For example, three equal columns would use three `.col-xs-4`.
15 | 如果一“行(row)”中包含了的“列(column)”大于 12,多余的“列(column)”所在的元素将被作为一个整体另起一行排列。
16 | Grid classes apply to devices with screen widths greater than or equal to the breakpoint sizes, and override grid classes targeted at smaller devices. Therefore, e.g. applying any `.col-md-*` class to an element will not only affect its styling on medium devices but also on large devices if a `.col-lg-*` class is not present.
17 | 通过研究后面的实例,可以将这些原理应用到你的代码中。
18 |
19 | ## 媒体查询
20 | 在栅格系统中,我们在 Less 文件中使用以下媒体查询(media query)来创建关键的分界点阈值。
21 |
22 | ```
23 | /* 超小屏幕(手机,小于 768px) */
24 | /* 没有任何媒体查询相关的代码,因为这在 Bootstrap 中是默认的(还记得 Bootstrap 是移动设备优先的吗?) */
25 |
26 | /* 小屏幕(平板,大于等于 768px) */
27 | @media (min-width: @screen-sm-min) { ... }
28 |
29 | /* 中等屏幕(桌面显示器,大于等于 992px) */
30 | @media (min-width: @screen-md-min) { ... }
31 |
32 | /* 大屏幕(大桌面显示器,大于等于 1200px) */
33 | @media (min-width: @screen-lg-min) { ... }
34 | ```
35 |
36 | 我们偶尔也会在媒体查询代码中包含 `max-width` 从而将 CSS 的影响限制在更小范围的屏幕大小之内。
37 |
38 | ```
39 | @media (max-width: @screen-xs-max) { ... }
40 | @media (min-width: @screen-sm-min) and (max-width: @screen-sm-max) { ... }
41 | @media (min-width: @screen-md-min) and (max-width: @screen-md-max) { ... }
42 | @media (min-width: @screen-lg-min) { ... }
43 | ```
44 | ## 栅格参数
45 | 通过下表可以详细查看 Bootstrap 的栅格系统是如何在多种屏幕设备上工作的。
46 |
47 | 超小屏幕 手机 (<768px) 小屏幕 平板 (≥768px) 中等屏幕 桌面显示器 (≥992px) 大屏幕 大桌面显示器 (≥1200px)
48 | 栅格系统行为 总是水平排列 开始是堆叠在一起的,当大于这些阈值时将变为水平排列C
49 | `.container` 最大宽度 None (自动) 750px 970px 1170px
50 | 类前缀 `.col-xs-` `.col-sm-` `.col-md-` `.col-lg-`
51 | 列(column)数 12
52 | 最大列(column)宽 自动 ~62px ~81px ~97px
53 | 槽(gutter)宽 30px (每列左右均有 15px)
54 | 可嵌套 是
55 | 偏移(Offsets) 是
56 | 列排序 是
57 | ## 实例:从堆叠到水平排列
58 | 使用单一的一组 `.col-md-*` 栅格类,就可以创建一个基本的栅格系统,在手机和平板设备上一开始是堆叠在一起的(超小屏幕到小屏幕这一范围),在桌面(中等)屏幕设备上变为水平排列。所有“列(column)必须放在 ” `.row` 内。
59 |
60 | .col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1.col-md-1
61 | .col-md-8.col-md-4
62 | .col-md-4.col-md-4.col-md-4
63 | .col-md-6.col-md-6
64 |
65 | ```
66 |
67 |
.col-md-1
68 |
.col-md-1
69 |
.col-md-1
70 |
.col-md-1
71 |
.col-md-1
72 |
.col-md-1
73 |
.col-md-1
74 |
.col-md-1
75 |
.col-md-1
76 |
.col-md-1
77 |
.col-md-1
78 |
.col-md-1
79 |
80 |
81 |
.col-md-8
82 |
.col-md-4
83 |
84 |
85 |
.col-md-4
86 |
.col-md-4
87 |
.col-md-4
88 |
89 |
90 |
.col-md-6
91 |
.col-md-6
92 |
93 | ```
94 | ## 实例:流式布局容器
95 | 将最外面的布局元素 `.container` 修改为 `.container-fluid`,就可以将固定宽度的栅格布局转换为 100% 宽度的布局。
96 |
97 | ```
98 |
99 |
100 | ...
101 |
102 |
103 | ```
104 | ## 实例:移动设备和桌面屏幕
105 | 是否不希望在小屏幕设备上所有列都堆叠在一起?那就使用针对超小屏幕和中等屏幕设备所定义的类吧,即 `.col-xs-*` 和 `.col-md-*`。请看下面的实例,研究一下这些是如何工作的。
106 |
107 | .col-xs-12 .col-md-8.col-xs-6 .col-md-4
108 | .col-xs-6 .col-md-4.col-xs-6 .col-md-4.col-xs-6 .col-md-4
109 | .col-xs-6.col-xs-6
110 |
111 | ```
112 |
113 |
114 |
.col-xs-12 .col-md-8
115 |
.col-xs-6 .col-md-4
116 |
117 |
118 |
119 |
120 |
.col-xs-6 .col-md-4
121 |
.col-xs-6 .col-md-4
122 |
.col-xs-6 .col-md-4
123 |
124 |
125 |
126 |
127 |
.col-xs-6
128 |
.col-xs-6
129 |
130 | ```
131 |
132 | ## 实例:手机、平板、桌面
133 | 在上面案例的基础上,通过使用针对平板设备的 `.col-sm-*` 类,我们来创建更加动态和强大的布局吧。
134 |
135 | .col-xs-12 .col-sm-6 .col-md-8.col-xs-6 .col-md-4
136 | .col-xs-6 .col-sm-4.col-xs-6 .col-sm-4.col-xs-6 .col-sm-4
137 |
138 | ```
139 |
140 |
.col-xs-12 .col-sm-6 .col-md-8
141 |
.col-xs-6 .col-md-4
142 |
143 |
144 |
.col-xs-6 .col-sm-4
145 |
.col-xs-6 .col-sm-4
146 |
147 |
148 |
.col-xs-6 .col-sm-4
149 |
150 | ```
151 |
152 | ## 实例:多余的列(column)将另起一行排列
153 | 如果在一个 `.row` 内包含的列(column)大于12个,包含多余列(column)的元素将作为一个整体单元被另起一行排列。
154 |
155 | .col-xs-9.col-xs-4
156 | Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit..col-xs-6
157 | Subsequent columns continue along the new line.
158 |
159 | ```
160 |
161 |
.col-xs-9
162 |
.col-xs-4 Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.
163 |
.col-xs-6 Subsequent columns continue along the new line.
164 |
165 | ```
166 |
167 | ## Responsive column resets
168 | With the four tiers of grids available you're bound to run into issues where, at certain breakpoints, your columns don't clear quite right as one is taller than the other. To fix that, use a combination of a `.clearfix` and our responsive utility classes.
169 |
170 | .col-xs-6 .col-sm-3
171 | Resize your viewport or check it out on your phone for an example. .col-xs-6 .col-sm-3.col-xs-6 .col-sm-3.col-xs-6 .col-sm-3
172 |
173 | ```
174 |
175 |
.col-xs-6 .col-sm-3
176 |
.col-xs-6 .col-sm-3
177 |
178 |
179 |
180 |
181 |
.col-xs-6 .col-sm-3
182 |
.col-xs-6 .col-sm-3
183 |
184 | ```
185 |
186 | In addition to column clearing at responsive breakpoints, you may need to **reset offsets, pushes, or pulls**. See this in action in the grid example.
187 |
188 | ```
189 |
190 |
.col-sm-5 .col-md-6
191 |
.col-sm-5 .col-sm-offset-2 .col-md-6 .col-md-offset-0
192 |
193 |
194 |
195 |
.col-sm-6 .col-md-5 .col-lg-6
196 |
.col-sm-6 .col-md-5 .col-md-offset-2 .col-lg-6 .col-lg-offset-0
197 |
198 | ```
199 |
200 | ## 列偏移
201 | 使用 `.col-md-offset-* `类可以将列向右侧偏移。这些类实际是通过使用 `* `选择器为当前元素增加了左侧的边距(margin)。例如,`.col-md-offset-4 `类将 `.col-md-4` 元素向右侧偏移了4个列(column)的宽度。
202 |
203 | .col-md-4.col-md-4 .col-md-offset-4
204 | .col-md-3 .col-md-offset-3.col-md-3 .col-md-offset-3
205 | .col-md-6 .col-md-offset-3
206 |
207 | ```
208 |
209 |
.col-md-4
210 |
.col-md-4 .col-md-offset-4
211 |
212 |
213 |
.col-md-3 .col-md-offset-3
214 |
.col-md-3 .col-md-offset-3
215 |
216 |
217 |
.col-md-6 .col-md-offset-3
218 |
219 | ```
220 |
221 | ## 嵌套列
222 | 为了使用内置的栅格系统将内容再次嵌套,可以通过添加一个新的 `.row` 元素和一系列 `.col-sm-*` 元素到已经存在的 `.col-sm-*` 元素内。被嵌套的行(row)所包含的列(column)的个数不能超过12(其实,没有要求你必须占满12列)。
223 |
224 | Level 1: .col-sm-9
225 | Level 2: .col-xs-8 .col-sm-6 Level 2: .col-xs-4 .col-sm-6
226 |
227 | ```
228 |
229 |
230 | Level 1: .col-sm-9
231 |
232 |
233 | Level 2: .col-xs-8 .col-sm-6
234 |
235 |
236 | Level 2: .col-xs-4 .col-sm-6
237 |
238 |
239 |
240 |
241 | ```
242 |
243 | ## 列排序
244 | 通过使用 `.col-md-push-*`和 `.col-md-pull-*` 类就可以很容易的改变列(column)的顺序。
245 |
246 | .col-md-9 .col-md-push-3.col-md-3 .col-md-pull-9
247 |
248 | ```
249 |
250 |
.col-md-9 .col-md-push-3
251 |
.col-md-3 .col-md-pull-9
252 |
253 | ```
254 | ## Less mixin 和变量
255 | 除了用于快速布局的预定义栅格类,Bootstrap 还包含了一组 Less 变量和 mixin 用于帮你生成简单、语义化的布局。
256 |
257 | ### 变量
258 |
259 | 通过变量来定义列数、槽(gutter)宽、媒体查询阈值(用于确定合适让列浮动)。我们使用这些变量生成预定义的栅格类,如上所示,还有如下所示的定制 mixin。
260 |
261 | ```
262 | @grid-columns: 12;
263 | @grid-gutter-width: 30px;
264 | @grid-float-breakpoint: 768px;
265 | ```
266 |
267 | ### mixin
268 |
269 |
270 | mixin 用来和栅格变量一同使用,为每个列(column)生成语义化的 CSS 代码。
271 |
272 | ```
273 | // Creates a wrapper for a series of columns
274 | .make-row(@gutter: @grid-gutter-width) {
275 | // Then clear the floated columns
276 | .clearfix();
277 |
278 | @media (min-width: @screen-sm-min) {
279 | margin-left: (@gutter / -2);
280 | margin-right: (@gutter / -2);
281 | }
282 |
283 | // Negative margin nested rows out to align the content of columns
284 | .row {
285 | margin-left: (@gutter / -2);
286 | margin-right: (@gutter / -2);
287 | }
288 | }
289 |
290 | // Generate the extra small columns
291 | .make-xs-column(@columns; @gutter: @grid-gutter-width) {
292 | position: relative;
293 | // Prevent columns from collapsing when empty
294 | min-height: 1px;
295 | // Inner gutter via padding
296 | padding-left: (@gutter / 2);
297 | padding-right: (@gutter / 2);
298 |
299 | // Calculate width based on number of columns available
300 | @media (min-width: @grid-float-breakpoint) {
301 | float: left;
302 | width: percentage((@columns / @grid-columns));
303 | }
304 | }
305 |
306 | // Generate the small columns
307 | .make-sm-column(@columns; @gutter: @grid-gutter-width) {
308 | position: relative;
309 | // Prevent columns from collapsing when empty
310 | min-height: 1px;
311 | // Inner gutter via padding
312 | padding-left: (@gutter / 2);
313 | padding-right: (@gutter / 2);
314 |
315 | // Calculate width based on number of columns available
316 | @media (min-width: @screen-sm-min) {
317 | float: left;
318 | width: percentage((@columns / @grid-columns));
319 | }
320 | }
321 |
322 | // Generate the small column offsets
323 | .make-sm-column-offset(@columns) {
324 | @media (min-width: @screen-sm-min) {
325 | margin-left: percentage((@columns / @grid-columns));
326 | }
327 | }
328 | .make-sm-column-push(@columns) {
329 | @media (min-width: @screen-sm-min) {
330 | left: percentage((@columns / @grid-columns));
331 | }
332 | }
333 | .make-sm-column-pull(@columns) {
334 | @media (min-width: @screen-sm-min) {
335 | right: percentage((@columns / @grid-columns));
336 | }
337 | }
338 |
339 | // Generate the medium columns
340 | .make-md-column(@columns; @gutter: @grid-gutter-width) {
341 | position: relative;
342 | // Prevent columns from collapsing when empty
343 | min-height: 1px;
344 | // Inner gutter via padding
345 | padding-left: (@gutter / 2);
346 | padding-right: (@gutter / 2);
347 |
348 | // Calculate width based on number of columns available
349 | @media (min-width: @screen-md-min) {
350 | float: left;
351 | width: percentage((@columns / @grid-columns));
352 | }
353 | }
354 |
355 | // Generate the medium column offsets
356 | .make-md-column-offset(@columns) {
357 | @media (min-width: @screen-md-min) {
358 | margin-left: percentage((@columns / @grid-columns));
359 | }
360 | }
361 | .make-md-column-push(@columns) {
362 | @media (min-width: @screen-md-min) {
363 | left: percentage((@columns / @grid-columns));
364 | }
365 | }
366 | .make-md-column-pull(@columns) {
367 | @media (min-width: @screen-md-min) {
368 | right: percentage((@columns / @grid-columns));
369 | }
370 | }
371 |
372 | // Generate the large columns
373 | .make-lg-column(@columns; @gutter: @grid-gutter-width) {
374 | position: relative;
375 | // Prevent columns from collapsing when empty
376 | min-height: 1px;
377 | // Inner gutter via padding
378 | padding-left: (@gutter / 2);
379 | padding-right: (@gutter / 2);
380 |
381 | // Calculate width based on number of columns available
382 | @media (min-width: @screen-lg-min) {
383 | float: left;
384 | width: percentage((@columns / @grid-columns));
385 | }
386 | }
387 |
388 | // Generate the large column offsets
389 | .make-lg-column-offset(@columns) {
390 | @media (min-width: @screen-lg-min) {
391 | margin-left: percentage((@columns / @grid-columns));
392 | }
393 | }
394 | .make-lg-column-push(@columns) {
395 | @media (min-width: @screen-lg-min) {
396 | left: percentage((@columns / @grid-columns));
397 | }
398 | }
399 | .make-lg-column-pull(@columns) {
400 | @media (min-width: @screen-lg-min) {
401 | right: percentage((@columns / @grid-columns));
402 | }
403 | }
404 | ```
405 |
406 | ## 实例展示
407 |
408 | 你可以重新修改这些变量的值,或者用默认值调用这些 mixin。下面就是一个利用默认设置生成两列布局(列之间有间隔)的案例。
409 |
410 | ```
411 | .wrapper {
412 | .make-row();
413 | }
414 | .content-main {
415 | .make-lg-column(8);
416 | }
417 | .content-secondary {
418 | .make-lg-column(3);
419 | .make-lg-column-offset(1);
420 | }
421 | ```
422 |
423 | ```
424 |
425 |
...
426 |
...
427 |
428 | ```
429 |
--------------------------------------------------------------------------------