Blogger Information
Blog 28
fans 0
comment 1
visits 21349
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML 第二课下拉菜单
南宫
Original
622 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. /* 为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制。通过从已设定的宽度和高度分别减去边框和内边距才能得到内容的宽度和高度。 */
  12. box-sizing: border-box;
  13. }
  14. a {
  15. color: #bbb;
  16. text-decoration: none;
  17. }
  18. #nav {
  19. background-color: black;
  20. height: 50px;
  21. line-height: 50px;
  22. }
  23. li {
  24. list-style: none;
  25. margin: 0 10px;
  26. float: left;
  27. }
  28. /* :hover 选择鼠标指针浮动在其上的元素,并设置其样式: */
  29. #nav > li > a:hover {
  30. color: white;
  31. }
  32. #nav > li {
  33. position: relative;
  34. }
  35. #nav > li > ul {
  36. position: absolute;
  37. top: 50px;
  38. width: 180px;
  39. border: 1px solid #aaa;
  40. border-top: none;
  41. }
  42. #nav > li > ul > li a {
  43. display: inline-block;
  44. height: 50px;
  45. color: #444;
  46. }
  47. ul.sub li:hover {
  48. background-color: #eee;
  49. }
  50. #nav > li > ul {
  51. display: none;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <ul id="nav">
  57. <li><a href="">首页</a></li>
  58. <li><a href="">视频教程</a></li>
  59. <li><a href="">入门教程</a></li>
  60. <li>
  61. <a href="">技术文章</a>
  62. <ul>
  63. <li><a href="">头条</a></li>
  64. <li><a href="">博客</a></li>
  65. <li><a href="">PHP教程</a></li>
  66. <li><a href="">PHP框架</a></li>
  67. </ul>
  68. </li>
  69. <li><a href="">社区问答</a></li>
  70. <li>
  71. <a href="">资源下载</a>
  72. <ul>
  73. <li><a href="">PHP工具</a></li>
  74. <li><a href="">在线手册</a></li>
  75. <li><a href="">学习课件</a></li>
  76. <li><a href="">网站源码</a></li>
  77. </ul>
  78. </li>
  79. <li><a href="">php培训</a></li>
  80. </ul>
  81. </body>
  82. <script>
  83. const navs = document.querySelectorAll("#nav > li");
  84. navs.forEach(function (nav) {
  85. //鼠标在标签上时事件
  86. nav.addEventListener("mouseover", showSubMenu);
  87. //鼠标在标签离开时事件
  88. nav.addEventListener("mouseout", hideSubMenu);
  89. });
  90. function showSubMenu(ev) {
  91. // ev.arget 事件属性可返回事件的目标节点(触发该事件的节点)
  92. // nextElementSibling 属性只返回元素节点之后的兄弟元素节点(不包括文本节点、注释节点);
  93. if (ev.target.nextElementSibling !== null) {
  94. ev.target.nextElementSibling.style.display = "block";
  95. }
  96. }
  97. function hideSubMenu(ev) {
  98. // nodeName 属性指定节点的节点名称。
  99. if (ev.target.nodeName === "A" && ev.target.nextElementSibling !== null) {
  100. ev.target.nextElementSibling.style.display = "none";
  101. }
  102. }
  103. </script>
  104. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:一个下拉菜单 , 不知难住了多少英雄好汉, 不怕, 今晚咱们再战
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post