欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

导航制作flex

程序员文章站 2022-03-03 23:25:01
...
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>flex练习</title>
  5. <meta name="keywords" content="html5,css3,js">
  6. <meta name="description" content="html5,css3,js,描述的内容">
  7. <style>
  8. body,ul
  9. {
  10. padding: 0;
  11. margin: 0;
  12. }
  13. li {list-style: none;}
  14. a{
  15. text-decoration: none;
  16. color: white;
  17. }
  18. .dh>ul{
  19. display: flex;
  20. justify-content: center;
  21. background-color: red;
  22. }
  23. .dh>ul>li{
  24. height: 40px;
  25. width: 80px;
  26. line-height: 40px;
  27. text-align: center;
  28. }
  29. .dh>ul>li:hover{
  30. background-color: brown;
  31. }
  32. .list{
  33. position: relative;
  34. }
  35. .list_1{
  36. background-color: red;
  37. width: 80px;
  38. position: absolute;
  39. left: 0px;
  40. display: none;
  41. }
  42. .list_1>li:hover{
  43. background-color: brown;
  44. }
  45. .list:hover .list_1{
  46. display: block;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <nav class="dh">
  52. <ul>
  53. <li><a href="#">要闻</a></li>
  54. <li><a href="#">国际</a></li>
  55. <li><a href="#">国内</a></li>
  56. <li><a href="#">娱乐</a></li>
  57. <li class="list"><a href="#">体育</a>
  58. <ul class="list_1">
  59. <li><a href="#">篮球</a></li>
  60. <li><a href="#">足球</a></li>
  61. <li><a href="#">羽毛球</a></li>
  62. <li><a href="#">网球</a></li>
  63. </ul>
  64. </li>
  65. <li><a href="#">军事</a></li>
  66. </ul>
  67. </nav>
  68. </body>
  69. </html>![](https://img.php.cn/upload/image/354/315/532/1636700782815960.png)