Bootstrap4 下拉菜单依赖于 popper.min.js。
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、成都网站设计、临洮网络推广、成都小程序开发、临洮网络营销、临洮企业策划、临洮品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供临洮建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com
下拉菜单是可切换的,是以列表格式显示链接的上下文菜单。
<
div
class
=
"
dropdown
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Dropdown button
button
>
<
div
class
=
"
dropdown-menu
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 1
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 2
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Link 3
a
>
div
>
div
>
尝试一下 »
.dropdown 类用来指定一个下拉菜单。
我们可以使用一个按钮或链接来打开下拉菜单, 按钮或链接需要添加 .dropdown-toggle 和 data-toggle="dropdown" 属性。
我们也可以在 标签中使用:
<
div
class
=
"
dropdown
"
>
<
a
class
=
"
btn btn-secondary dropdown-toggle
"
href
=
"
#
"
role
=
"
button
"
id
=
"
dropdownMenuLink
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
Dropdown link
a
>
<
div
class
=
"
dropdown-menu
"
aria-labelledby
=
"
dropdownMenuLink
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Action
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Another action
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Something else here
a
>
div
>
div
>
尝试一下 »
.dropdown-divider 类用于在下拉菜单中创建一个水平的分割线:
<
div
class
=
"
dropdown-divider
"
>
div
>
尝试一下 »
.dropdown-header 类用于在下拉菜单中添加标题:
<
div
class
=
"
dropdown-header
"
>
Dropdown header 1
div
>
尝试一下 »
.active 类会让下拉菜单的选项高亮显示 (添加蓝色背景)。
如果要禁用下拉菜单的选项,可以使用.disabled 类。
<
a
class
=
"
dropdown-item active
"
href
=
"
#
"
>
Active
a
>
<
a
class
=
"
dropdown-item disabled
"
href
=
"
#
"
>
Disabled
a
>
尝试一下 »
如果我们想让下拉菜单右对齐,可以在元素上的 .dropdown-menu 类后添加 .dropdown-menu-right 类。
<
div
class
=
"
dropdown-menu dropdown-menu-right
"
>
尝试一下 »
下拉菜单弹出方向默认为向下,当然我们也可以设置不同的方向。
如果你希望下拉菜单向右弹出,可以在 div 元素上添加 "dropright" 类:
<
div
class
=
"
btn-group dropright
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
Dropright
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
<
div
class
=
"
btn-group dropright
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary
"
>
Split dropright
button
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle dropdown-toggle-split
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
<
span
class
=
"
sr-only
"
>
Toggle Dropright
span
>
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
尝试一下 »
如果你希望上拉菜单向上弹出,可以在 div 元素上添加 "dropup" 类:
<
div
class
=
"
btn-group dropup
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
Dropup
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
<
div
class
=
"
btn-group dropup
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary
"
>
Split dropup
button
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle dropdown-toggle-split
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
<
span
class
=
"
sr-only
"
>
Toggle Dropdown
span
>
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
尝试一下 »
如果你希望下拉菜单向上弹出,可以在 div 元素上添加 "dropleft" 类:
<
div
class
=
"
btn-group dropleft
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
Dropleft
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
<
div
class
=
"
btn-group
"
>
<
div
class
=
"
btn-group dropleft
"
role
=
"
group
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary dropdown-toggle dropdown-toggle-split
"
data-toggle
=
"
dropdown
"
aria-haspopup
=
"
true
"
aria-expanded
=
"
false
"
>
<
span
class
=
"
sr-only
"
>
Toggle Dropleft
span
>
button
>
<
div
class
=
"
dropdown-menu
"
>
div
>
div
>
<
button
type
=
"
button
"
class
=
"
btn btn-secondary
"
>
Split dropleft
button
>
div
>
尝试一下 »
.dropdown-item-text 类可以设置下拉菜单中的文本项:
<
div
class
=
"
dropdown-menu
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
链接 1
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
链接 2
a
>
<
a
class
=
"
dropdown-item-text
"
href
=
"
#
"
>
文本链接
a
>
<
span
class
=
"
dropdown-item-text
"
>
仅仅是文本
span
>
div
>
尝试一下 »
我们可以在按钮中添加下拉菜单:
<
div
class
=
"
btn-group
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary
"
>
Sony
button
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary dropdown-toggle dropdown-toggle-split
"
data-toggle
=
"
dropdown
"
>
<
span
class
=
"
caret
"
>
span
>
button
>
<
div
class
=
"
dropdown-menu
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Tablet
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Smartphone
a
>
div
>
div
>
尝试一下 »
垂直按钮组带下拉菜单:
<
div
class
=
"
btn-group-vertical
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary
"
>
Apple
button
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary
"
>
Samsung
button
>
<
div
class
=
"
btn-group
"
>
<
button
type
=
"
button
"
class
=
"
btn btn-primary dropdown-toggle
"
data-toggle
=
"
dropdown
"
>
Sony
button
>
<
div
class
=
"
dropdown-menu
"
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Tablet
a
>
<
a
class
=
"
dropdown-item
"
href
=
"
#
"
>
Smartphone
a
>
div
>
div
>
div
>
尝试一下 »
当前文章:创新互联Bootstrap4教程:Bootstrap4下拉菜单
本文路径:http://www.csdahua.cn/qtweb/news30/223480.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网