关键词搜索

源码搜索 ×
×

BootStrap笔记-折叠的使用

发布2022-01-24浏览809次

详情内容

运行截图如下:

代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>CN_TEST1</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- bootstrap css核心文件-->
  8. <link rel="stylesheet" href="bootstrap-4.4.1-dist/css/bootstrap.min.css">
  9. <!-- bootstrap使用到了jquery,需要提前引用-->
  10. <script src="js/jquery-3.5.1.min.js"></script>
  11. <!-- 弹窗、提示、下拉菜单-->
  12. <script src="bootstrap-4.4.1-dist/js/bootstrap.bundle.js"></script>
  13. <!-- bootstrap核心文件-->
  14. <script src="bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
  15. </head>
  16. <body>
  17. <div class="container-fluid">
  18. <button data-toggle="collapse" data-target="#demo">折叠</button>
  19. <div id="demo" class="collapse">
  20. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  21. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  22. </div>
  23. <br/>
  24. <a href="#demo2" data-toggle="collapse">Collapsible</a>
  25. <div id="demo2" class="collapse">
  26. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  27. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  28. </div>
  29. <br/>
  30. <!-- 风琴实例-->
  31. <div id="accordion">
  32. <div class="card">
  33. <div class="card-header">
  34. <a class="card-link" data-toggle="collapse" href="#collapseOne">
  35. 选项一
  36. </a>
  37. </div>
  38. <div id="collapseOne" class="collapse show" data-parent="#accordion">
  39. <div class="card-body">
  40. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  41. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello
  42. </div>
  43. </div>
  44. </div>
  45. <div class="card">
  46. <div class="card-header">
  47. <a class="card-link" data-toggle="collapse" href="#collapseTwo">
  48. 选项二
  49. </a>
  50. </div>
  51. <div id="collapseTwo" class="collapse show" data-parent="#accordion">
  52. <div class="card-body">
  53. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  54. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello
  55. </div>
  56. </div>
  57. </div>
  58. <div class="card">
  59. <div class="card-header">
  60. <a class="card-link" data-toggle="collapse" href="#collapseThree">
  61. 选项三
  62. </a>
  63. </div>
  64. <div id="collapseThree" class="collapse show" data-parent="#accordion">
  65. <div class="card-body">
  66. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
  67. Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </body>
  74. </html>

解释:

①在div中使用collapse类指定折叠元素。点击按钮会显示和隐藏的话,需要在a或button上添加data-toggle="collapse"属性,data-target="#id"属性是对应折叠内容;

②<a>元素上可以使用href属性来代替data-target;

③data-parent属性来确保所有的折叠元素在指定的父元素下,这样就能实现在一个折叠选项显示其他选项就隐藏。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载