本章將討論 Bootstrap 中的一些可能會派上用場的輔助類。
以下不同的類展示了不同的文本顏色。如果文本是個鏈接鼠標(biāo)移動到文本上會變暗:
類 | 描述 | 實(shí)例 |
---|---|---|
.text-muted | "text-muted" 類的文本樣式 | 嘗試一下 |
.text-primary | "text-primary" 類的文本樣式 | 嘗試一下 |
.text-success | "text-success" 類的文本樣式 | 嘗試一下 |
.text-info | "text-info" 類的文本樣式 | 嘗試一下 |
.text-warning | "text-warning" 類的文本樣式 | 嘗試一下 |
.text-danger | "text-danger" 類的文本樣式 | 嘗試一下 |
以下不同的類展示了不同的背景顏色。 如果文本是個鏈接鼠標(biāo)移動到文本上會變暗:
類 | 描述 | 實(shí)例 |
---|---|---|
.bg-primary | 表格單元格使用了 "bg-primary" 類 | 嘗試一下 |
.bg-success | 表格單元格使用了 "bg-success" 類 | 嘗試一下 |
.bg-info | 表格單元格使用了 "bg-info" 類 | 嘗試一下 |
.bg-warning | 表格單元格使用了 "bg-warning" 類 | 嘗試一下 |
.bg-danger | 表格單元格使用了 "bg-danger" 類 | 嘗試一下 |
類 | 描述 | 實(shí)例 |
---|---|---|
.pull-left | 元素浮動到左邊 | 嘗試一下 |
.pull-right | 元素浮動到右邊 | 嘗試一下 |
.center-block | 設(shè)置元素為 display:block 并居中顯示 | 嘗試一下 |
.clearfix | 清除浮動 | 嘗試一下 |
.show | 強(qiáng)制元素顯示 | 嘗試一下 |
.hidden | 強(qiáng)制元素隱藏 | 嘗試一下 |
.sr-only | 除了屏幕閱讀器外,其他設(shè)備上隱藏元素 | 嘗試一下 |
.sr-only-focusable | 與 .sr-only 類結(jié)合使用,在元素獲取焦點(diǎn)時顯示(如:鍵盤操作的用戶) | 嘗試一下 |
.text-hide | 將頁面元素所包含的文本內(nèi)容替換為背景圖 | 嘗試一下 |
.close | 顯示關(guān)閉按鈕 | 嘗試一下 |
.caret | 顯示下拉式功能 | 嘗試一下 |
使用通用的關(guān)閉圖標(biāo)來關(guān)閉模態(tài)框和警告框。使用 class close 得到關(guān)閉圖標(biāo)。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 關(guān)閉圖標(biāo)</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><p>關(guān)閉圖標(biāo)實(shí)例 <button type="button" class="close" aria-hidden="true">
× </button></p></body></html>
結(jié)果如下所示:
使用插入符表示下拉功能和方向。使用帶有 class caret 的 <span> 元素得到該功能。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 插入符</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><p>插入符實(shí)例 <span class="caret"></span></p></body></html>
結(jié)果如下所示:
您可以分別使用 class pull-left 或 pull-right 來把元素向左或向右浮動。下面的實(shí)例演示了這點(diǎn)。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 快速浮動</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><div class="pull-left">
向左快速浮動</div><div class="pull-right">
向右快速浮動</div></body></html>
結(jié)果如下所示:
如需對齊導(dǎo)航欄中的組件,請使用 .navbar-left 或 .navbar-right 代替。請查看 Bootstrap 導(dǎo)航欄。
使用 class center-block 來居中元素。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 居中內(nèi)容塊</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><div class="row">
<div class="center-block" style="width:200px;background-color:#ccc;">
這是 center-block 實(shí)例 </div></div></body></html>
結(jié)果如下所示:
如需清除元素的浮動,請使用 .clearfix class。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 清除浮動</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><div class="clearfix" style="background: #D8D8D8;border: 1px solid #000;padding: 10px;">
<div class="pull-left" style="background:#58D3F7;">
向左快速浮動 </div>
<div class="pull-right" style="background: #DA81F5;">
向右快速浮動 </div></div></body></html>
結(jié)果如下所示:
您可以通過使用 class .show 和 .hidden 來強(qiáng)行設(shè)置元素顯示或隱藏(包括屏幕閱讀器)。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 顯示和隱藏內(nèi)容</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><div class="row" style="padding: 91px 100px 19px 50px;">
<div class="show" style="left-margin:10px;width:300px;background-color:#ccc;">
這是 show class 的實(shí)例 </div>
<div class="hidden" style="width:200px;background-color:#ccc;">
這是 hide class 的實(shí)例 </div></div></body></html>
結(jié)果如下所示:
您可以通過使用 class .sr-only 來把元素對所有設(shè)備隱藏,除了屏幕閱讀器。
<!DOCTYPE html><html><head>
<title>Bootstrap 實(shí)例 - 屏幕閱讀器</title>
<link rel="stylesheet" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ></script></head><body><div class="row" style="padding: 91px 100px 19px 50px;">
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="email">Email 地址</label>
<input type="email" class="form-control" placeholder="Enter email">
</div>
<div class="form-group">
<label class="sr-only" for="pass">密碼</label>
<input type="password" class="form-control" placeholder="Password">
</div>
</form></div></body></html>
結(jié)果如下所示:
在這里,我們看到兩個 input 類型的 label 標(biāo)簽都帶有 class sr-only,因此標(biāo)簽將只對屏幕閱讀器可見。
更多建議: