Bootstrap 輔助類
本章將討論 Bootstrap 中的一些可能會(huì)派上用場(chǎng)的輔助類。
文本
以下不同的類展示了不同的文本顏色。如果文本是個(gè)鏈接鼠標(biāo)移動(dòng)到文本上會(huì)變暗:
類 | 描述 | 實(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" 類的文本樣式 | 嘗試一下 |
背景
以下不同的類展示了不同的背景顏色。 如果文本是個(gè)鏈接鼠標(biāo)移動(dòng)到文本上會(huì)變暗:
類 | 描述 | 實(shí)例 |
---|---|---|
.bg-primary | 表格單元格使用了 "bg-primary" 類 | 嘗試一下 |
.bg-success | 表格單元格使用了 "bg-success" 類 | 嘗試一下 |
.bg-info | 表格單元格使用了 "bg-info" 類 | 嘗試一下 |
.bg-warning | 表格單元格使用了 "bg-warning" 類 | 嘗試一下 |
.bg-danger | 表格單元格使用了 "bg-danger" 類 | 嘗試一下 |
其他
類 | 描述 | 實(shí)例 |
---|---|---|
.pull-left | 元素浮動(dòng)到左邊 | 嘗試一下 |
.pull-right | 元素浮動(dòng)到右邊 | 嘗試一下 |
.center-block | 設(shè)置元素為 display:block 并居中顯示 | 嘗試一下 |
.clearfix | 清除浮動(dòng) | |
.show | 強(qiáng)制元素顯示 | 嘗試一下 |
.hidden | 強(qiáng)制元素隱藏 | 嘗試一下 |
.sr-only | 除了屏幕閱讀器外,其他設(shè)備上隱藏元素 | 嘗試一下 |
.sr-only-focusable | 與 .sr-only 類結(jié)合使用,在元素獲取焦點(diǎn)時(shí)顯示(如:鍵盤操作的用戶) | 嘗試一下 |
.text-hide | 將頁(yè)面元素所包含的文本內(nèi)容替換為背景圖 | 嘗試一下 |
.close | 顯示關(guān)閉按鈕 | 嘗試一下 |
.caret | 顯示下拉式功能 | 嘗試一下 |
更多實(shí)例
關(guān)閉圖標(biāo)
使用通用的關(guān)閉圖標(biāo)來關(guān)閉模態(tài)框和警告框。使用 class close 得到關(guān)閉圖標(biāo)。
<html>
<head>
<title>Bootstrap 實(shí)例 - 關(guān)閉圖標(biāo)</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<p>關(guān)閉圖標(biāo)實(shí)例
<button type="button" class="close" aria-hidden="true">
×
</button>
</p>
</body>
</html>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 關(guān)閉圖標(biāo)</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <p>關(guān)閉圖標(biāo)實(shí)例 <button type="button" class="close" aria-hidden="true"> × </button> </p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
插入符
<html>
<head>
<title>Bootstrap 實(shí)例 - 插入符</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<p>插入符實(shí)例
<span class="caret"></span>
</p>
</body>
</html>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 插入符</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <p>插入符實(shí)例 <span class="caret"></span> </p> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
快速浮動(dòng)
您可以分別使用 class pull-left 或 pull-right 來把元素向左或向右浮動(dòng)。下面的實(shí)例演示了這點(diǎn)。
<html>
<head>
<title>Bootstrap 實(shí)例 - 快速浮動(dòng)</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="pull-left">
向左快速浮動(dòng)
</div>
<div class="pull-right">
向右快速浮動(dòng)
</div>
</body>
</html>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 快速浮動(dòng)</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <div class="pull-left"> 向左快速浮動(dòng) </div> <div class="pull-right"> 向右快速浮動(dòng) </div> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
如需對(duì)齊導(dǎo)航欄中的組件,請(qǐng)使用 .navbar-left 或 .navbar-right 代替。請(qǐng)查看 Bootstrap 導(dǎo)航欄。
內(nèi)容居中
使用 class center-block 來居中元素。
<html>
<head>
<title>Bootstrap 實(shí)例 - 居中內(nèi)容塊</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="center-block" style="width:200px;background-color:#ccc;">
這是 center-block 實(shí)例
</div>
</div>
</body>
</html>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 居中內(nèi)容塊</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <div class="row"> <div class="center-block" style="width:200px;background-color:#ccc;"> 這是 center-block 實(shí)例 </div> </div> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
清除浮動(dòng)
如需清除元素的浮動(dòng),請(qǐng)使用 .clearfix class。
<html>
<head>
<title>Bootstrap 實(shí)例 - 清除浮動(dòng)</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="clearfix" style="background: #D8D8D8;border: 1px solid #000;padding: 10px;">
<div class="pull-left" style="background:#58D3F7;">
向左快速浮動(dòng)
</div>
<div class="pull-right" style="background: #DA81F5;">
向右快速浮動(dòng)
</div>
</div>
</body>
</html>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 清除浮動(dòng)</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> </head> <body> <div class="clearfix" style="background: #D8D8D8;border: 1px solid #000;padding: 10px;"> <div class="pull-left" style="background:#58D3F7;"> 向左快速浮動(dòng) </div> <div class="pull-right" style="background: #DA81F5;"> 向右快速浮動(dòng) </div> </div> </body> </html>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
顯示和隱藏內(nèi)容
您可以通過使用 class .show 和 .hidden 來強(qiáng)行設(shè)置元素顯示或隱藏(包括屏幕閱讀器)。
<html>
<head>
<title>Bootstrap 實(shí)例 - 顯示和隱藏內(nèi)容</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></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>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 顯示和隱藏內(nèi)容</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></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>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
屏幕閱讀器
您可以通過使用 class .sr-only 來把元素對(duì)所有設(shè)備隱藏,除了屏幕閱讀器。
<html>
<head>
<title>Bootstrap 實(shí)例 - 屏幕閱讀器</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://apps.bdimg.com/libs/bootstrap/3.3.0/js/bootstrap.min.js"></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>
實(shí)例
<!DOCTYPE html> <html> <head> <title>Bootstrap 實(shí)例 - 屏幕閱讀器</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></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>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例