- Bootstrap 教程
- Bootstrap - 首页
- Bootstrap - 概述
- Bootstrap - 环境设置
- Bootstrap - 从右到左 (RTL)
- Bootstrap - CSS 变量
- Bootstrap - 色彩模式
- Bootstrap 布局
- Bootstrap - 断点
- Bootstrap - 容器
- Bootstrap - 网格系统
- Bootstrap - 列
- Bootstrap - 间距
- Bootstrap - 实用工具
- Bootstrap - CSS 网格
- Bootstrap 组件
- Bootstrap - 手风琴
- Bootstrap - 警报
- Bootstrap - 徽章
- Bootstrap - 面包屑
- Bootstrap - 按钮
- Bootstrap - 按钮组
- Bootstrap - 卡片
- Bootstrap - 走马灯
- Bootstrap - 关闭按钮
- Bootstrap - 折叠
- Bootstrap - 下拉菜单
- Bootstrap - 列表组
- Bootstrap - 模态框
- Bootstrap - 导航栏
- Bootstrap - 导航 & 标签
- Bootstrap - 侧边栏
- Bootstrap - 分页
- Bootstrap - 占位符
- Bootstrap - 气泡提示
- Bootstrap - 进度条
- Bootstrap - 滚动侦听
- Bootstrap - 加载动画
- Bootstrap - 提示框
- Bootstrap - 工具提示
- Bootstrap 表单
- Bootstrap - 表单
- Bootstrap - 表单控件
- Bootstrap - 选择框
- Bootstrap - 复选框 & 单选按钮
- Bootstrap - 范围滑块
- Bootstrap - 输入组
- Bootstrap - 浮动标签
- Bootstrap - 布局
- Bootstrap - 验证
- Bootstrap 辅助工具
- Bootstrap - 清除浮动
- Bootstrap - 颜色 & 背景
- Bootstrap - 彩色链接
- Bootstrap - 聚焦环
- Bootstrap - 图标链接
- Bootstrap - 定位
- Bootstrap - 宽高比
- Bootstrap - 堆叠
- Bootstrap - 拉伸链接
- Bootstrap - 文本截断
- Bootstrap - 垂直线
- Bootstrap - 视觉隐藏
- Bootstrap 实用工具
- Bootstrap - 背景
- Bootstrap - 边框
- Bootstrap - 颜色
- Bootstrap - 显示
- Bootstrap - Flex 布局
- Bootstrap - 浮动
- Bootstrap - 交互
- Bootstrap - 链接
- Bootstrap - 对象适应
- Bootstrap - 不透明度
- Bootstrap - 溢出
- Bootstrap - 定位
- Bootstrap - 阴影
- Bootstrap - 尺寸
- Bootstrap - 间距
- Bootstrap - 文本
- Bootstrap - 垂直对齐
- Bootstrap - 可见性
- Bootstrap 演示
- Bootstrap - 网格演示
- Bootstrap - 按钮演示
- Bootstrap - 导航演示
- Bootstrap - 博客演示
- Bootstrap - 滑块演示
- Bootstrap - 走马灯演示
- Bootstrap - 页眉演示
- Bootstrap - 页脚演示
- Bootstrap - 英雄区演示
- Bootstrap - 特色演示
- Bootstrap - 侧边栏演示
- Bootstrap - 下拉菜单演示
- Bootstrap - 列表组演示
- Bootstrap - 模态框演示
- Bootstrap - 徽章演示
- Bootstrap - 面包屑演示
- Bootstrap - 超大标题演示
- Bootstrap-粘性页脚演示
- Bootstrap-相册演示
- Bootstrap-登录演示
- Bootstrap-定价演示
- Bootstrap-结账演示
- Bootstrap-产品演示
- Bootstrap-封面演示
- Bootstrap-仪表盘演示
- Bootstrap-粘性页脚导航栏演示
- Bootstrap-砌体布局演示
- Bootstrap-启动模板演示
- Bootstrap-相册 RTL 演示
- Bootstrap-结账 RTL 演示
- Bootstrap-走马灯 RTL 演示
- Bootstrap-博客 RTL 演示
- Bootstrap-仪表盘 RTL 演示
- Bootstrap 有用资源
- Bootstrap - 常见问题解答
- Bootstrap - 快速指南
- Bootstrap - 有用资源
- Bootstrap - 讨论
Bootstrap - 手风琴
本章将讨论 Bootstrap 手风琴。手风琴垂直折叠元素,通过类更改显示和隐藏。使用 collapse JavaScript 插件创建垂直折叠的手风琴。
工作原理
为了折叠,手风琴在内部使用 collapse。使用 .open 类到 .accordion 元素以呈现展开的手风琴。
基本示例
要展开和折叠内容,请点击下面的手风琴。
您可以使用 编辑 & 运行 选项编辑和尝试运行此代码。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Accordion</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <style> </style> </head> <body> <div class="accordion" id="basicAccordion"> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#firstCollapse" aria-expanded="true" aria-controls="firstCollapse"> Bootstrap - Accordian </button> </h2> <div id="firstCollapse" class="accordion-collapse collapse show" data-bs-parent="#basicAccordion"> <div class="accordion-body"> The <b>accordion</b> collapses elements vertically, shown and hidden by class change. </div> </div> </div> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#secondCollapse" aria-expanded="false" aria-controls="secondCollapse"> Bootstrap - Buttons </button> </h2> <div id="secondCollapse" class="accordion-collapse collapse" data-bs-parent="#basicAccordion"> <div class="accordion-body"> You can use Bootstrap’s custom button styles for actions in forms, dialogs and many more. </div> </div> </div> </div> </body> </html>
无边距
要呈现边缘到边缘的手风琴,请使用 .accordion-flush 删除边框和圆角。
您可以使用 编辑 & 运行 选项编辑和尝试运行此代码。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Accordion</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <style> </style> </head> <body> <div class="accordion accordion-flush" id="flushAccordion"> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flushCollapseOne" aria-expanded="false" aria-controls="flushCollapseOne"> Bootstrap - Accordian </button> </h2> <div id="flushCollapseOne" class="accordion-collapse collapse" data-bs-parent="#flushAccordion"> <div class="accordion-body"> The <b>accordion</b> collapses elements vertically, shown and hidden by class change. </div> </div> </div> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flushCollapseTwo" aria-expanded="false" aria-controls="flushCollapseTwo"> Bootstrap - Buttons </button> </h2> <div id="flushCollapseTwo" class="accordion-collapse collapse" data-bs-parent="#flushAccordion"> <div class="accordion-body"> You can use Bootstrap’s custom button styles for actions in forms, dialogs and many more. </div> </div> </div> </div> </div> </body> </html>
始终打开
要保持手风琴项目在另一个项目打开时保持打开状态,请从每个 .accordion-collapse 中删除 data-bs-parent 属性。
您可以使用 编辑 & 运行 选项编辑和尝试运行此代码。
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Accordion</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <style> </style> </head> <body> <div class="accordion" id="alwaysOpenAccordion"> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#firstCollpaseofAlwaysOpen" aria-expanded="true" aria-controls="firstCollpaseofAlwaysOpen"> Bootstrap - Accordian </button> </h2> <div id="firstCollpaseofAlwaysOpen" class="accordion-collapse collapse show"> <div class="accordion-body"> The <b>accordion</b> collapses elements vertically, shown and hidden by class change. </div> </div> </div> <div class="accordion-item"> <h2 class="accordion-header"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#secondCollpaseofAlwaysOpen" aria-expanded="false" aria-controls="secondCollpaseofAlwaysOpen"> Bootstrap - Buttons </button> </h2> <div id="secondCollpaseofAlwaysOpen" class="accordion-collapse collapse"> <div class="accordion-body"> The <b>accordion</b> collapses elements vertically, shown and hidden by class change. </div> </div> </div> </div> </body> </html>
可访问性
有关详细信息,请参阅 collapse 可访问性部分。
广告