创新互联Bootstrap教程:Bootstrap按钮下拉菜单

Bootstrap 按钮下拉菜单

本章将讲解如何使用 Bootstrap class 向按钮添加下拉菜单。如需向按钮添加下拉菜单,只需要简单地在一个 .btn-group 容器中放置按钮和下拉菜单即可。您也可以使用 来指示按钮作为下拉菜单。

10年的玉林网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整玉林建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“玉林网站设计”,“玉林网站推广”以来,每个客户项目都认真落实执行。

下面的实例演示了一个基本的简单的按钮下拉菜单:

实例

<
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
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-primary dropdown-toggle
"

data-toggle
=
"
dropdown
"
>
原始
<
span

class
=
"
caret
"
>
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

尝试一下 »

结果如下所示:

分割的按钮下拉菜单

分割的按钮下拉菜单使用与下拉菜单按钮大致相同的样式,但是对下拉菜单添加了原始的功能。分割按钮的左边是原始的功能,右边是显示下拉菜单的切换。

实例

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-default
"
>
默认
button
>

<
button

type
=
"
button
"

class
=
"
btn btn-default dropdown-toggle
"

data-toggle
=
"
dropdown
"
>

<
span

class
=
"
caret
"
>
span
>

<
span

class
=
"
sr-only
"
>
切换下拉菜单
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>
<
a

href
=
"
#
"
>
功能
a
>
li
>

<
li
>
<
a

href
=
"
#
"
>
另一个功能
a
>
li
>

<
li
>
<
a

href
=
"
#
"
>
其他
a
>
li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>
<
a

href
=
"
#
"
>
分离的链接
a
>
li
>

ul
>

div
>

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-primary
"
>
原始
button
>

<
button

type
=
"
button
"

class
=
"
btn btn-primary dropdown-toggle
"

data-toggle
=
"
dropdown
"
>

<
span

class
=
"
caret
"
>
span
>

<
span

class
=
"
sr-only
"
>
切换下拉菜单
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>
<
a

href
=
"
#
"
>
功能
a
>
li
>

<
li
>
<
a

href
=
"
#
"
>
另一个功能
a
>
li
>

<
li
>
<
a

href
=
"
#
"
>
其他
a
>
li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>
<
a

href
=
"
#
"
>
分离的链接
a
>
li
>

ul
>

div
>

尝试一下 »

结果如下所示:

按钮下拉菜单的大小

您可以使用带有各种大小按钮的下拉菜单:.btn-lg、.btn-sm .btn-xs

实例

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-default dropdown-toggle btn-lg
"

data-toggle
=
"
dropdown
"
>
默认
<
span

class
=
"
caret
"
>
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-primary dropdown-toggle btn-sm
"

data-toggle
=
"
dropdown
"
>
原始
<
span

class
=
"
caret
"
>
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

<
div

class
=
"
btn-group
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-success dropdown-toggle btn-xs
"

data-toggle
=
"
dropdown
"
>
成功
<
span

class
=
"
caret
"
>
span
>
button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

尝试一下 »

结果如下所示:

按钮上拉菜单

菜单也可以往上拉伸的,只需要简单地向父 .btn-group 容器添加 .dropup 即可。

实例

<
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
"
>
默认
<
span

class
=
"
caret
"
>
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

<
div

class
=
"
btn-group dropup
"
>

<
button

type
=
"
button
"

class
=
"
btn btn-primary dropdown-toggle
"

data-toggle
=
"
dropdown
"
>
原始
<
span

class
=
"
caret
"
>
span
>

button
>

<
ul

class
=
"
dropdown-menu
"

role
=
"
menu
"
>

<
li
>

<
a

href
=
"
#
"
>
功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
另一个功能
a
>

li
>

<
li
>

<
a

href
=
"
#
"
>
其他
a
>

li
>

<
li

class
=
"
divider
"
>
li
>

<
li
>

<
a

href
=
"
#
"
>
分离的链接
a
>

li
>

ul
>

div
>

div
>

尝试一下 »

结果如下所示:

文章名称:创新互联Bootstrap教程:Bootstrap按钮下拉菜单
网页URL:http://www.mswzjz.cn/qtweb/news45/239695.html

攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能