7.3.4 按钮组嵌套下拉菜单
如果希望在按钮组中嵌套下拉菜单,则只要在按钮组容器中添加按钮式下拉菜单即可—也就是在.btn-group
容器中再次放置.btn-group
构建的下拉菜单。
程序示例
例如如下代码在按钮组中嵌套.btn-group
构建的下拉菜单。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <!DOCTYPE html> <html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title> 按钮组嵌套下拉菜单 </title> <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css"> </head>
<body> <div class="container"> <div class="btn-group" role="group"> <button type="button" class="btn btn-primary">主页</button> <button type="button" class="btn btn-primary">联系我们</button> <div class="btn-group"> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdown1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> 图书管理 <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdown1"> <li><a href="#">新增图书</a></li> <li><a href="#">修改图书</a></li> <li><a href="#">删除图书</a></li> <li role="separator" class="divider"></li> <li><a href="#">查找图书</a></li> </ul> </div> <div class="btn-group"> <button class="btn btn-primary" type="button">作者管理</button> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdown2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span> <span class="sr-only">打开作者管理</span> </button> <ul class="dropdown-menu" aria-labelledby="dropdown2"> <li><a href="#">添加作者</a></li> <li><a href="#">修改作者</a></li> <li role="separator" class="divider"></li> <li><a href="#">查找作者</a></li> </ul> </div> </div> </div> <script type="text/javascript" src="../jquery-3.1.1.js"></script> <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script> </body>
</html>
|
垂直排列的按钮组嵌套按钮式下拉菜单
Bootstrap
支持垂直排列的按钮组,因此垂直排列的按钮组中也可嵌套按钮式下拉菜单,只要将按钮组的样式改为.btn-group-vertical
即可。
注意:**在垂直排列的按钮组中嵌套按钮式下拉菜单时,不支持嵌套分裂式按钮下拉菜单
**。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <!DOCTYPE html> <html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title> 按钮组嵌套下拉菜单 </title> <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css"> </head>
<body> <div class="container"> <div class="btn-group-vertical" role="group"> <button type="button" class="btn btn-primary">主页</button> <button type="button" class="btn btn-primary">联系我们</button> <div class="btn-group"> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdown1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> 图书管理 <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdown1"> <li><a href="#">新增图书</a></li> <li><a href="#">修改图书</a></li> <li><a href="#">删除图书</a></li> <li role="separator" class="divider"></li> <li><a href="#">查找图书</a></li> </ul> </div> <div class="btn-group"> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdown2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> 作者管理 <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdown2"> <li><a href="#">添加作者</a></li> <li><a href="#">修改作者</a></li> <li role="separator" class="divider"></li> <li><a href="#">查找作者</a></li> </ul> </div> </div> </div> <script type="text/javascript" src="../jquery-3.1.1.js"></script> <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script> </body>
</html>
|