Bootstrap 按鈕組
按鈕群組允許多個按鈕被堆疊在同一行上。當你想要把按鈕對齊在一起時,這就顯得非常有用。您可以透過 Bootstrap 按鈕(Button) 外掛程式 新增可選的 JavaScript 單選框和複選框樣式行為。
下面的表格總結了Bootstrap 提供的使用按鈕群組的一些重要的class:
Class | 描述 | 程式碼範例 |
---|---|---|
.btn-group | 該class 用來形成基本的按鈕群組。在 .btn-group 中放置一系列帶有 class .btn 的按鈕。 | <div class="btn-group"> <button type="button" class="btn btn-default">Button1</button> <button type="button" class="btn btn-default">Button2</button> </div> |
.btn-toolbar | 該class 有助於把幾組<div class="btn-group"> 結合到一個<div class="btn-toolbar"> 中,一般會得到更複雜的元件。 | <div class="btn-toolbar" role="toolbar"> <div class="btn-group">...</div> <div class="btn-group">...</div> </div> |
.btn-group-lg, .btn-group-sm, .btn-group-xs | 這些class 可應用到整個按鈕組的大小調整,而不需要對每個按鈕進行大小調整。 | <div class="btn-group btn-group-lg">...</div> <div class="btn-group btn-group-sm">...</div> <div class="btn-group btn-group-xs">...</div> |
.btn-group-vertical | 該 class 讓一組按鈕垂直堆疊顯示,而不是水平堆疊顯示。 | <div class="btn-group-vertical"> ... </div> |
基本的按鈕群組
下面的實例示範了上面表格中討論到的class .btn-group 的使用:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 基本的按鈕組</title>##1link //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="btn-group">
<button type="button" class= "btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
1 button" class="btn btn-default">按鈕 3</button>
</div>
</body>
</html>
<html>
<head>
<title>Bootstrap 實例 - 基本的按鈕組</title>##1link //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="btn-group">
<button type="button" class= "btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
1 button" class="btn btn-default">按鈕 3</button>
</div>
</body>
</html>
##實例
運行實例»點擊"運行實例" 按鈕查看線上實例#實例
運行實例»
點擊"運行實例"按鈕查看線上實例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap 实例 - 基本的按钮组</title> <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="btn-group"> <button type="button" class="btn btn-default">按钮 1</button> <button type="button" class="btn btn-default">按钮 2</button> <button type="button" class="btn btn-default">按钮 3</button> </div> </body> </html>
運行實例»點擊"運行實例" 按鈕查看線上實例#
按鈕工具列
下面的實例示範了上面表格中討論到的class .btn-toolbar 的使用:
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 按鈕工具列</title>
.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="btn-toolbar" role="toolbar">
<div class="btn-group" >
<button type="button" class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
<button type="button" class="btn btn-default">按鈕 3</button>
</div>
class=" btn-group">
<button type="button" class="btn btn-default">按鈕 4</button>
<button type="button"1class="btnbtn-tn default">按鈕 5</button>
<button type="button" class="btn btn-default">按鈕 6</button>
> div class="btn-group">
<button type="button" class="btn btn-default">按鈕 7</button>
< "btn btn-default">按鈕 8</button>
<button type="button" class="btn btn-default">按鈕 9</button>
< ##</div>
</body>
</html>
<html>
<head>
<title>Bootstrap 實例 - 按鈕工具列</title>
.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="btn-toolbar" role="toolbar">
<div class="btn-group" >
<button type="button" class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
<button type="button" class="btn btn-default">按鈕 3</button>
</div>
class=" btn-group">
<button type="button" class="btn btn-default">按鈕 4</button>
<button type="button"1class="btnbtn-tn default">按鈕 5</button>
<button type="button" class="btn btn-default">按鈕 6</button>
> div class="btn-group">
<button type="button" class="btn btn-default">按鈕 7</button>
< "btn btn-default">按鈕 8</button>
<button type="button" class="btn btn-default">按鈕 9</button>
< ##</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bootstrap 实例 - 按钮工具栏</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="btn-toolbar" role="toolbar">
<div class="btn-group">
<button type="button" class="btn btn-default">按钮 1</button>
<button type="button" class="btn btn-default">按钮 2</button>
<button type="button" class="btn btn-default">按钮 3</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">按钮 4</button>
<button type="button" class="btn btn-default">按钮 5</button>
<button type="button" class="btn btn-default">按钮 6</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default">按钮 7</button>
<button type="button" class="btn btn-default">按钮 8</button>
<button type="button" class="btn btn-default">按钮 9</button>
</div>
</div>
</body>
</html>
運行實例»點擊"運行實例"按鈕查看線上實例
按鈕的大小
下面的實例示範了上面表格中討論到的class .btn-group-* 的使用:
< !DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 按鈕組的大小<);/titled 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="btn-group btn-group-lg">
<button type="button " class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default"> …2</button>#lto btn-default"> 2</button>#1; type="button" class="btn btn-default">按鈕 3</button>
</div>
<div class="btn-group btn-group-sm">
# <button type="button" class="btn btn-default">按鈕 4</button>
<button type="button" class="btn b;按鈕-default">button type="button" class="btn b;按鈕-default"> /button>
<button type="button" class="btn btn-default">按鈕 6</button>
</div>
</button>
</div>
< btn-group-xs">
<button type="button" class="btn btn-default">按鈕 7</button>
<button type="button" class="btn btn-default">按鈕 8</button>
<button type="button" class="btn btn-default">按鈕 9</button>
</#>
</body>
</html>
<html>
<head>
<title>Bootstrap 實例 - 按鈕組的大小<);/titled 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="btn-group btn-group-lg">
<button type="button " class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default"> …2</button>#lto btn-default"> 2</button>#1; type="button" class="btn btn-default">按鈕 3</button>
</div>
<div class="btn-group btn-group-sm">
# <button type="button" class="btn btn-default">按鈕 4</button>
<button type="button" class="btn b;按鈕-default">button type="button" class="btn b;按鈕-default"> /button>
<button type="button" class="btn btn-default">按鈕 6</button>
</div>
</button>
</div>
< btn-group-xs">
<button type="button" class="btn btn-default">按鈕 7</button>
<button type="button" class="btn btn-default">按鈕 8</button>
<button type="button" class="btn btn-default">按鈕 9</button>
</#>
</body>
</html>
#實例
執行實例»點擊"運行實例" 按鈕查看線上實例
運行實例»
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap 实例 - 按钮组的大小</title> <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="btn-group btn-group-lg"> <button type="button" class="btn btn-default">Button 1</button> <button type="button" class="btn btn-default">Button 2</button> <button type="button" class="btn btn-default">Button 3</button> </div> <div class="btn-group btn-group-sm"> <button type="button" class="btn btn-default">Button 4</button> <button type="button" class="btn btn-default">Button 5</button> <button type="button" class="btn btn-default">Button 6</button> </div> <div class="btn-group btn-group-xs"> <button type="button" class="btn btn-default">Button 7</button> <button type="button" class="btn btn-default">Button 8</button> <button type="button" class="btn btn-default">Button 9</button> </div> </body> </html>
執行實例»點擊"運行實例" 按鈕查看線上實例
嵌套
您可以在一個按鈕組內嵌套另一個按鈕組,即,在一個.btn-group 內嵌套另一個.btn- group 。當您向讓下拉式選單與一系列按鈕組合使用時,就會用到這個。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 嵌套的按鈕組</title>Bootstrap 實例 - 嵌套的按鈕組</title>#title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script: src="http="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="btn-group">
<button type="button" class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕2< ;
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle ">
下列為
<span class="caret"></span>
# <li><a href="#">下拉連結 1</a></li>a
< ;</li>
</ul>
</div>
</div>
#</body>
</html>
#</body>
< <html>
<head>
<title>Bootstrap 實例 - 嵌套的按鈕組</title>Bootstrap 實例 - 嵌套的按鈕組</title>#title>
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script: src="http="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="btn-group">
<button type="button" class="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕2< ;
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle ">
下列為
<span class="caret"></span>
# <li><a href="#">下拉連結 1</a></li>a
< ;</li>
</ul>
</div>
</div>
#</body>
</html>
#</body>
##實例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap 实例 - 嵌套的按钮组</title> <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="btn-group"> <button type="button" class="btn btn-default">按钮 1</button> <button type="button" class="btn btn-default">按钮 2</button> <div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> 下列 <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#">下拉链接 1</a></li> <li><a href="#">下拉链接 2</a></li> </ul> </div> </div> </body> </html>
運行實例»
點擊"運行實例"按鈕查看線上實例
垂直的按鈕組
下面的實例示範了上面表格中討論到的class .btn-group-vertical 的使用:
< ;!DOCTYPE html>
<html>
<head>
<title>Bootstrap 實例 - 垂直的按鈕組</title>##1< /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="btn-group-vertical">
<button type="button" class ="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
lt; div class="btn-group-vertical">
<button type="button" class="btn btn-default dropdown-toggle"
<span class="caret"></span>
</button>
a href="#">下拉連結 1</a></li>
<li><a href="#">下拉連結…2</a><a href="#">下拉連結2</a></li></li></li></li></li></li></li></li></li></li></li></li></li>< ## </ul>
</div>
</div>
</body>
</html>
<html>
<head>
<title>Bootstrap 實例 - 垂直的按鈕組</title>##1< /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="btn-group-vertical">
<button type="button" class ="btn btn-default">按鈕 1</button>
<button type="button" class="btn btn-default">按鈕 2</button>
lt; div class="btn-group-vertical">
<button type="button" class="btn btn-default dropdown-toggle"
<span class="caret"></span>
</button>
a href="#">下拉連結 1</a></li>
<li><a href="#">下拉連結…2</a><a href="#">下拉連結2</a></li></li></li></li></li></li></li></li></li></li></li></li></li>< ## </ul>
</div>
</div>
</body>
</html>
1;
#點擊"運行實例" 按鈕查看線上實例#實例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Bootstrap 实例 - 垂直的按钮组</title> <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="btn-group-vertical"> <button type="button" class="btn btn-default">按钮 1</button> <button type="button" class="btn btn-default">按钮 2</button> <div class="btn-group-vertical"> <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> 下拉 <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#">下拉链接 1</a></li> <li><a href="#">下拉链接 2</a></li> </ul> </div> </div> </body> </html>
執行實例»