[前端] HTML+CSS实现导航条下拉菜单的示例代码

1933 0
Honkers 2022-10-19 15:35:56 | 显示全部楼层 |阅读模式
效果

代码中的图片可以自己换的


下拉菜单HTML代码
  1. <header class="header">
  2.         <div class="header_left">
  3.             <img src="img/logo.jpg">
  4.         </div>
  5.         <div class="header_right">
  6.                 <div class="number_right">
  7.                     <img src="img/number.jpg">
  8.                 </div>
  9.                 <ul>
  10.                     <a href="#"><li>首页</li></a>
  11.                     <a href="#"><li class="show_list">
  12.                         <span>成功案例</span>
  13.                         <ul class="move_list">
  14.                             <li>品牌设计</li>
  15.                             <li>网页设计</li>
  16.                             <li>平面设计</li>
  17.                             <li>电子商城</li>
  18.                             <li>空间/建筑</li>
  19.                         </ul>
  20.                     </li></a>
  21.                     <a href="#"><li>我要设计</li></a>
  22.                     <a href="#"><li>在线咨询</li></a>
  23.                     <a href="#"><li>会员注册</li></a>
  24.                     <a href="#"><li>会员登录</li></a>
  25.                 </ul>
  26.         </div>
  27.     </header>
复制代码
下拉菜单CSS代码
  1. .header{
  2.     height: 120px;
  3.     width: 1046px;
  4.     margin: 0 auto;
  5. }
  6. .header_left{
  7.     float: left;
  8.     line-height: 120px;
  9. }
  10. .header_left img{
  11.     width: 300px;
  12.     height: 100px;
  13. }
  14. .header_right{
  15.     float: right;
  16.     height: 120px;
  17.     position: relative;
  18. }
  19. .header_right>div{
  20.     position: absolute;
  21.     top: 0;
  22.     right: 0;
  23. }
  24. .header_right ul{
  25.     margin-top: 88px;
  26. }
  27. .header_right ul a li{
  28.     border-right: 1px solid #000000;
  29.     height: 13px;
  30.     font-size: 15px;
  31.     padding: 0 25px;
  32.     font-weight: bold;
  33.     color: #666;
  34. }
  35. .header_right ul a{
  36.     float: left;
  37.     line-height: 13px;
  38. }
  39. .header_right ul a li:hover{
  40.     color: #000000;
  41. }
  42. .header_right ul a:last-child li{/*去掉最后的边框*/
  43.     border: none;
  44. }
  45. .show_list{
  46.     position: relative;
  47. }
  48. .show_list .move_list{
  49.     display: none;
  50.     z-index: 103;
  51.     position: absolute;
  52.     top: -56px;
  53.     left: 0;
  54.     width: 100%;
  55.     background: #333;
  56.     text-align: center;
  57. }
  58. .show_list .move_list li{
  59.     padding: 10px 0;
  60.     width: 114px;
  61.     color: #fff;
  62. }
  63. .header_right ul a .show_list{
  64.     padding-bottom: 20px;
  65.     border-right: none;
  66. }
  67. .show_list:hover .move_list{
  68.     display: block;
  69. }
  70. .header_right ul a:nth-child(3){
  71.     border-left: 1px solid #000;
  72. }
  73. .show_list .move_list li:hover{
  74.     color: white;
  75.     background: orange;
  76. }
复制代码
在写完上述代码的同时须加上css的重置代码,代码如下:
  1. * {
  2.     margin: 0;
  3.     padding: 0
  4. }
  5. em,i {
  6.     font-style: normal
  7. }
  8. li {
  9.     list-style: none
  10. }
  11. a{
  12.     font: 14px/24px Microsoft YaHei,Arial,\\5B8B\4F53,Arial Narrow;
  13.     letter-spacing: 1.2px;
  14.     color: #666;
  15.     text-decoration: none
  16. }
  17. a:hover {
  18.     color: #c81623 ;
  19. }
  20. img {
  21.     border: 0;
  22.     vertical-align: middle
  23. }
  24. input{
  25.     outline: none;
  26. }
  27. button {
  28.     cursor: pointer;
  29.     border:none;
  30.     outline: none;
  31. }
复制代码
到此这篇关于HTML+CSS实现导航条下拉菜单的示例代码的文章就介绍到这了,更多相关HTML+CSS导航条下拉菜单内容请搜索中国红客联盟以前的文章或继续浏览下面的相关文章,希望大家以后多多支持中国红客联盟!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行