本章將重點介紹 Bootstrap 下拉菜單。下拉菜單是可切換的,是以列表格式顯示連接的上下文菜單。這能夠經過與 下拉菜單(Dropdown) JavaScript 插件 的互動來實現。php
如需使用下列菜單,只須要在 class .dropdown 內加上下拉菜單便可。下面的實例演示了基本的下拉菜單:css
<!DOCTYPE html> <html> <head> <title>Bootstrap 實例 - 下拉菜單(Dropdowns)</title> <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <script src="/scripts/jquery.min.js"></script> <script src="/bootstrap/js/bootstrap.min.js"></script> </head> <body> <div class="dropdown"> <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown"> 主題 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">Java</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">數據挖掘</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#"> 數據通訊/網絡 </a> </li> <li role="presentation" class="divider"></li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">分離的連接</a> </li> </ul> </div> </body> </html>
嘗試一下 »html
結果以下所示:jquery
經過向 .dropdown-menu 添加 class .pull-right 來向右對齊下拉菜單。下面的實例演示了這點:bootstrap
<!DOCTYPE html> <html> <head> <title>Bootstrap 實例 - 向右對齊下拉菜單</title> <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <script src="/scripts/jquery.min.js"></script> <script src="/bootstrap/js/bootstrap.min.js"></script> </head> <body> <div class="dropdown"> <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown">主題 <span class="caret"></span> </button> <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1"> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">Java</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">數據挖掘</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#"> 數據通訊/網絡 </a> </li> <li role="presentation" class="divider"></li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">分離的連接</a> </li> </ul> </div> </body> </html>
嘗試一下 »網絡
結果以下所示:ide
您能夠使用 class dropdown-header 向下拉菜單的標籤區域添加標題。下面的實例演示了這點:ui
<!DOCTYPE html> <html> <head> <title>Bootstrap 實例 - 下拉菜單標題</title> <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <script src="/scripts/jquery.min.js"></script> <script src="/bootstrap/js/bootstrap.min.js"></script> </head> <body> <div class="dropdown"> <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown"> 主題 <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1"> <li role="presentation" class="dropdown-header">下拉菜單標題</li> <li role="presentation" > <a role="menuitem" tabindex="-1" href="#">Java</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">數據挖掘</a> </li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#"> 數據通訊/網絡 </a> </li> <li role="presentation" class="divider"></li> <li role="presentation" class="dropdown-header">下拉菜單標題</li> <li role="presentation"> <a role="menuitem" tabindex="-1" href="#">分離的連接</a> </li> </ul> </div> </body> </html>
嘗試一下 »spa
結果以下所示:插件
原文地址:http://www.phplearn.cn/bootstrap/bootstrap-dropdowns.html