• 基于html、css、javascript的选项卡网页设计


    1. html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta
    6. name="viewport"
    7. content="width=device-width, initial-scale=1.0"
    8. >
    9. <meta
    10. http-equiv="X-UA-Compatible"
    11. content="ie=edge"
    12. >
    13. <title>基于html、css、javascript的选项卡title>
    14. <style>
    15. * {
    16. margin: 0;
    17. padding: 0;
    18. }
    19. body {
    20. background-color: aquamarine;
    21. }
    22. ul,
    23. ol,
    24. li {
    25. list-style: none;
    26. }
    27. .tab {
    28. width: 600px;
    29. height: 400px;
    30. border: 10px solid yellow;
    31. margin: 50px auto;
    32. display: flex;
    33. flex-direction: column;
    34. }
    35. ul {
    36. height: 60px;
    37. display: flex;
    38. }
    39. ul>li {
    40. flex: 1;
    41. display: flex;
    42. justify-content: center;
    43. align-items: center;
    44. font-size: 40px;
    45. color: #fff;
    46. background-color: cyan;
    47. cursor: pointer;
    48. }
    49. ul>li.active {
    50. background-color: orange;
    51. }
    52. ol {
    53. flex: 1;
    54. position: relative;
    55. }
    56. ol>li {
    57. position: absolute;
    58. left: 0;
    59. top: 0;
    60. width: 100%;
    61. height: 100%;
    62. font-size: 100px;
    63. color: #fff;
    64. background-color: cornsilk;
    65. display: none;
    66. justify-content: center;
    67. align-items: center;
    68. }
    69. ol>li.active {
    70. display: flex;
    71. }
    72. style>
    73. head>
    74. <body>
    75. <div class="tab">
    76. <ul>
    77. <li class="active">1li>
    78. <li>2li>
    79. <li>3li>
    80. ul>
    81. <ol>
    82. <li class="active">1li>
    83. <li>2li>
    84. <li>3li>
    85. ol>
    86. div>
    87. <script>
    88. function Tabs(ele) {
    89. this.ele = document.querySelector(ele)
    90. this.btns = this.ele.querySelectorAll('ul > li')
    91. this.tabs = this.ele.querySelectorAll('ol > li')
    92. }
    93. Tabs.prototype.change = function () {
    94. var _this = this
    95. for (var i = 0; i < this.btns.length; i++) {
    96. this.btns[i].setAttribute('index', i)
    97. this.btns[i].addEventListener('click', function () {
    98. for (var j = 0; j < _this.btns.length; j++) {
    99. _this.btns[j].className = ''
    100. _this.tabs[j].className = ''
    101. }
    102. this.className = 'active'
    103. var index = this.getAttribute('index') - 0
    104. _this.tabs[index].className = 'active'
    105. })
    106. }
    107. }
    108. var t = new Tabs('.tab')
    109. t.change()
    110. script>
    111. body>
    112. html>

     

  • 相关阅读:
    关于笔试编程题被坑的输入问题,acm模式下的python输入究竟如何写?
    golang 2018,go 1.19安装Gin
    vscode c/c++ 检测到 #include 错误。请更新 includePath。
    猿创征文 第二季| #「笔耕不辍」--生命不息,写作不止#
    LINUX|ubuntu常用指令
    算法通关村——字符串反转问题解析
    kafka启动报错
    基于Springcloud搭建电商平台实现高性能高并发微服务
    MySQL性能优化
    Kubernetes(K8S) kubesphere 介绍
  • 原文地址:https://blog.csdn.net/Protinx/article/details/126793713