辅助类


情境文本颜色

通过颜色来展示意图,Bootstrap 提供了一组工具类。这些类可以应用于链接,并且在鼠标经过时颜色可以还可以加深,就像默认的链接一样。

Fusce dapibus, tellus ac cursus commodo, tortor mauris nibh.

Nullam id dolor id nibh ultricies vehicula ut id elit.

Duis mollis, est non commodo luctus, nisi erat porttitor ligula.

Maecenas sed diam eget risus varius blandit sit amet non magna.

Etiam porta sem malesuada magna mollis euismod.

Donec ullamcorper nulla non metus auctor fringilla.

```

...

...

...

...

...

...

```

处理差异
Sometimes emphasis classes cannot be applied due to the specificity of another selector. In most cases, a sufficient workaround is to wrap your text in a <span> with the class.

Conveying meaning to assistive technologies
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (the contextual colors are only used to reinforce meaning that is already present in the text/markup), or is included through alternative means, such as additional text hidden with the .sr-only class.

情境背景色

和情境文本颜色类一样,使用任意情境背景色类就可以设置元素的背景。链接组件在鼠标经过时颜色会加深,就像上面所讲的情境文本颜色类一样。

Nullam id dolor id nibh ultricies vehicula ut id elit.

Duis mollis, est non commodo luctus, nisi erat porttitor ligula.

Maecenas sed diam eget risus varius blandit sit amet non magna.

Etiam porta sem malesuada magna mollis euismod.

Donec ullamcorper nulla non metus auctor fringilla.

```

...

...

...

...

...

```

处理差异
Sometimes contextual background classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element's content in a

with the class.

Conveying meaning to assistive technologies
As with contextual colors, ensure that any meaning conveyed through color is also conveyed in a format that is not purely presentational.

关闭按钮

通过使用一个象征关闭的图标,可以让模态框和警告框消失。

``` ```

三角符号

通过使用三角符号可以指示某个元素具有下拉菜单的功能。注意,向上弹出式菜单中的三角符号是反方向的。

``` ```

快速浮动

通过添加一个类,可以将任意元素向左或向右浮动。!important 被用来明确 CSS 样式的优先级。这些类还可以作为 mixin(参见 less 文档) 使用。

```
...
...
```
``` // Classes .pull-left { float: left !important; } .pull-right { float: right !important; }

// Usage as mixins .element { .pull-left(); } .another-element { .pull-right(); }


> **不能用于导航条组件中**<br/>
排列导航条中的组件时可以使用这些工具类:`.navbar-left` 或 `.navbar-right` 。 参见导航条文档以获取更多信息。

## 让内容块居中

为任意元素设置 `display: block` 属性并通过 `margin` 属性让其中的内容居中。下面列出的类还可以作为 `mixin` 使用。

<div style="height:1px;background:#ccc;"></div>
...
```
``` // Class .center-block { display: block; margin-left: auto; margin-right: auto; }

// Usage as a mixin .element { .center-block(); }


## 清除浮动

通过为父元素添加 `.clearfix` 类可以很容易地清除浮动(float)。这里所使用的是 Nicolas Gallagher 创造的 micro clearfix 方式。此类还可以作为 mixin 使用。

<div style="height:1px;background:#ccc;"></div>
...
// Mixin itself .clearfix() { &:before, &:after { content: " "; display: table; } &:after { clear: both; } }

// Usage as a mixin .element { .clearfix(); }


## 显示或隐藏内容

`.show` 和 `.hidden` 类可以强制任意元素显示或隐藏(对于屏幕阅读器也能起效)。这些类通过 !important 来避免 CSS 样式优先级问题,就像 quick floats 一样的做法。注意,这些类只对块级元素起作用,另外,还可以作为 mixin 使用。

`.hide` 类仍然可用,但是它不能对屏幕阅读器起作用,并且从 v3.0.1 版本开始就不建议使用了。请使用 `.hidden` 或 `.sr-only` 。

另外,`.invisible` 类可以被用来仅仅影响元素的可见性,也就是说,元素的 display 属性不被改变,并且这个元素仍然能够影响文档流的排布。

<div style="height:1px;background:#ccc;"></div>
...
```
``` // Classes .show { display: block !important; } .hidden { display: none !important; } .invisible { visibility: hidden; }

// Usage as mixins .element { .show(); } .another-element { .hidden(); }


## 屏幕阅读器和键盘导航

`.sr-only` 类可以对屏幕阅读器以外的设备隐藏内容。`.sr-only` 和 `.sr-only-focusable` 联合使用的话可以在元素有焦点的时候再次显示出来(例如,使用键盘导航的用户)。对于遵循 可访问性的最佳实践 很有必要。这个类也可以作为 mixin 使用。

<div style="height:1px;background:#ccc;"></div>

Skip to main content


<div style="height:5px;"></div>

<div style="height:1px;background:#ccc;"></div>

// Usage as a mixin .skip-navigation { .sr-only(); .sr-only-focusable(); }


## 图片替换

使用 `.text-hide` 类或对应的 mixin 可以用来将元素的文本内容替换为一张背景图。

<div style="height:1px;background:#ccc;"></div>

Custom heading

// Usage as a mixin .heading { .text-hide(); } ```

目录