目录

Bootstrap - 按钮下降( Button Drop downs)

本章将讨论如何使用Bootstrap类向按钮添加下拉菜单。 要向按钮添加下拉列表,只需将按钮和下拉菜单包装在.btn-group 。 您还可以使用“span class =”caret“”“/ span”作为按钮是下拉列表的指示符。

以下示例演示了基本的单按钮下拉菜单 -

<div class = "btn-group">
   <button type = "button" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">
      Default 
      <span class = "caret"></span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
<div class = "btn-group">
   <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">
      Primary 
      <span class = "caret"></span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
新页面打开

拆分按钮下拉菜单

拆分按钮下拉菜单使用与下拉按钮相同的常规样式,但添加主要操作以及下拉列表。 拆分按钮左侧有主要操作,右侧有切换按钮,显示下拉列表。

<div class = "btn-group">
   <button type = "button" class = "btn btn-default">Default</button>
   <button type = "button" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">
      <span class = "caret"></span>
      <span class = "sr-only">Toggle Dropdown</span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
<div class = "btn-group">
   <button type = "button" class = "btn btn-primary">Primary</button>
   <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">
      <span class = "caret"></span>
      <span class = "sr-only">Toggle Dropdown</span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
新页面打开

按钮下拉大小

您可以使用任何按钮大小的下拉列表 - .btn-large, .btn-sm,.btn-xs

<div class = "btn-group">
   <button type = "button" class = "btn btn-default dropdown-toggle btn-lg" data-toggle = "dropdown">
      Default
      <span class = "caret"></span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
<div class = "btn-group">
   <button type = "button" class = "btn btn-primary dropdown-toggle btn-sm" data-toggle = "dropdown">
      Primary
      <span class = "caret"></span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
<div class = "btn-group">
   <button type = "button" class = "btn btn-success dropdown-toggle btn-xs" data-toggle = "dropdown">
      Success
      <span class = "caret"></span>
   </button>
   <ul class = "dropdown-menu" role = "menu">
      <li><a href = "#">Action</a></li>
      <li><a href = "#">Another action</a></li>
      <li><a href = "#">Something else here</a></li>
      <li class = "divider"></li>
      <li><a href = "#">Separated link</a></li>
   </ul>
</div>
新页面打开

降落变化

菜单也可以建立起来而不是下降。 要实现此目的,只需将.dropup添加到父.btn-group容器即可。

<div class = "row" style = "margin-left:50px; margin-top:200px">
   <div class = "btn-group dropup">
      <button type = "button" class = "btn btn-default dropdown-toggle" data-toggle = "dropdown">
         Default
         <span class = "caret"></span>
      </button>
      <ul class = "dropdown-menu" role = "menu">
         <li><a href = "#">Action</a></li>
         <li><a href = "#">Another action</a></li>
         <li><a href = "#">Something else here</a></li>
         <li class = "divider"></li>
         <li><a href = "#">Separated link</a></li>
      </ul>
   </div>
   <div class = "btn-group dropup">
      <button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">
         Primary
         <span class = "caret"></span>
      </button>
      <ul class = "dropdown-menu" role = "menu">
         <li><a href = "#">Action</a></li>
         <li><a href = "#">Another action</a></li>
         <li><a href = "#">Something else here</a></li>
         <li class = "divider"></li>
         <li><a href = "#">Separated link</a></li>
      </ul>
   </div>
</div>
新页面打开
↑回到顶部↑
WIKI教程 @2018