flex语法简单的导航栏

编辑: admin 分类: 电脑知识 发布时间: 2023-06-14 来源:互联网
这是用flex编写的简单导航栏

直接上代码吧

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>grid演示</title>
  8. </head>
  9. <body>
  10. <div class="content">
  11. <header>
  12. <nav>
  13. <a href="">首页</a>
  14. <a href="">视频</a>
  15. <a href="">社区</a>
  16. <a href="">文章</a>
  17. <a href="">咨询</a>
  18. <a href="">简介</a>
  19. <a href="">源码</a>
  20. <a href="">作业</a>
  21. <a href="">下载</a>
  22. </nav>
  23. <button>登陆</button>
  24. </header>
  25. </div>
  26. <footer class="footer">页脚</footer>
  27. <style>
  28. .box {
  29. width: 100%;
  30. height: 2000px;
  31. }
  32. header {
  33. height: 80px;
  34. background-color: rgb(248, 244, 244);
  35. padding: 0 5em;
  36. display: flex;
  37. place-content: space-between;
  38. position: sticky;
  39. top: 0;
  40. color: #0c0202;
  41. }
  42. nav {
  43. display: flex;
  44. /* 水平垂直居中 */
  45. text-align: center;
  46. line-height: 80px;
  47. }
  48. nav a {
  49. min-width: 5em;
  50. color: #0c0505;
  51. text-decoration: none;
  52. flex: 1;
  53. }
  54. nav a:hover {
  55. color: white;
  56. background-color: aqua;
  57. transition: 0.3s;
  58. }
  59. header button {
  60. border: none;
  61. width: 5em;
  62. background-color: rgb(3, 5, 4);
  63. color: azure;
  64. }
  65. header button:hover {
  66. cursor: pointer;
  67. background-color: rgb(22, 228, 228);
  68. }
  69. footer {
  70. width: 100%;
  71. height: 50px;
  72. color: #ccc;
  73. background-color: black;
  74. text-align: center;
  75. line-height: 50px;
  76. }
  77. .box .title {
  78. height: 50px;
  79. font-weight: bolder;
  80. border: 1px solid #f5f1f1;
  81. background-color: rgb(10, 10, 10);
  82. }
  83. .box .content {
  84. min-width: 100%;
  85. min-height: 0px;
  86. background-color: #eee;
  87. }
  88. .box .title {
  89. /* 滚动到top=0就会自动停止并固定在当前位置 */
  90. position: sticky;
  91. top: 0;
  92. color: #9b9292;
  93. line-height: 50px;
  94. padding: 0 20em;
  95. }
  96. .box1 {
  97. width: 100px;
  98. height: 500px;
  99. display: flex;
  100. border: 1px solid #e0e4de6b;
  101. place-content: space-evenly;
  102. flex-flow: column nowrap;
  103. position: fixed;
  104. top: 5cm;
  105. bottom: 0;
  106. /* line-height: 50px; */
  107. border-radius: 20px 20px 20px 20px;
  108. }
  109. .box1 a {
  110. width: 100%;
  111. height: 25px;
  112. letter-spacing: 2px;
  113. text-align: center;
  114. text-decoration: none;
  115. color: #9b9292;
  116. /* flex: 1 1 auto; */
  117. }
  118. .box1 a:hover {
  119. color: white;
  120. background-color: rgb(70, 184, 159);
  121. transition: 0.1s;
  122. }
  123. </style>
  124. </body>
  125. </html>
  • 下面是效果图,如有错误请各位老师和大佬多多指教!

【文章原创作者盐城网站设计公司 http://www.1234xp.com/yancheng.html 提供,感恩】