CSS HTML中菜单栏的下拉列表

3

我希望为每个菜单添加下拉列表,但只有“产品”菜单显示。首先我只为“产品”菜单制作了下拉列表。但对于其他的菜单,它没有起作用。

HTML代码如下:

<!doctype html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Welcome to Cctvcart store</title>
      <link rel="stylesheet" href="css/style.css" type="text/css">
    </head>
    <body>
    <div class="header_wrap">
        <div class="header_top_wrap">
          <div class="header_top">
          </div>
        </div>
        <!--end of header top wrap -->
        <div class="header_bottom_wrap">
          <div class="header_bottom">
            <ul class="bottom_menu">
              <li class="dropdown"><li><a href="#">Company</a>

              <ul class="submenu">
                  <li><a href="#">About us</a>
                  </li>
 <li><a href="#">New Realeses</a>
                  </li>
 <li><a href="#">Contact us</a>
                  </li>
              </ul>
               </li>
              <li class="dropdown"><a  href="#">Products</a>
                <ul class="submenu">
                  <li><a href="#">DVR & Kits</a>
                  </li>
                  <li><a href="#">Seurity Cameras</a>
                  </li>
                  <li><a href="#">Spy Camreas</a></li>
                   <li><a href="#">Wireless & IP Cameras</a></li>
                    <li><a href="#">Accessories</a></li>
                     <li><a href="#">Mini Video</a></li>
                </ul>
              </li>

              <li><a href="#">Services</a>

              </li>
              <li class="dropdown"><li><a href="#">Support</a>
                <ul class="submenu">
                  <li><a href="#">Support Home</a>
                  </li>
 <li><a href="#">Warranty</a>
                  </li>
<li><a href="#">Feedback</a>
                  </li>
<li><a href="#">Contact Tech Support</a>
                  </li>

              </li>
             <li class="dropdown"> <li><a href="#">Multimedia</a>
   <ul class="submenu">
                  <li><a href="#">Video</a>
                  </li>
 <li><a href="#">Podcasts</a>
                  </li>
              </li>
            </ul>
           </div>
        </div>
        <!--end of bottom  wrap -->
      </div>
      <!--end of header wrap -->
      <div class="main_wrap">
        <div class="main">
        </div>
        <!--end of main  -->
      </div>
      <!--end of main wrap -->
      <div class="footer_wrap">
        <footer></footer>
      </div>
      <!--end of footer wrap -->
      </body>
      </html>

style.css:

 * {
       margin: 0px;
       padding: 0px;
     }
     .header_wrap {
       width: 100%;
       height: 160px;
       background: red;
       position: relative;
     }
     .main_wrap {
       width: 100%;
       height: 1475px;
       background: green;
     }
     .footer_wrap {
       width: 100%;
       height: 325px;
       background: aqua;
     }
     .main {
       width: 1000px;
       height: 100%;
       background: blue;
       margin: auto;
     }
     footer {
       width: 1000px;
       height: 100%;
       background: aqua;
       margin: auto;
     }
     .header_top_wrap {
       width: 100%;
       height: 23px;
       background: #ccc;
     }
     .header_bottom_wrap {
       width: 100%;
       height: 40px;
       background: #06F;
       position: absolute;
       bottom: 0px;
       left: 0px;
     }
     .header_top {
       width: 1000px;
       height: 100%;
       background: purple;
       margin: auto;
     }
     .header_bottom {
       width: 1000px;
       height: 100%;
       background: black;
       margin: auto;
     }
     .bottom_menu > li {
       display: inline-block;
     }
     .bottom_menu a
     {
         font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
         color: #fff;

     }
     .bottom_menu > li >a {
       display: block;
       text-decoration: none;


       padding: 0px 30px;
       height: 40px;
       line-height: 35px;
       text-align: center;
     }
    .bottom_menu > li:hover >a
    {
        background:#fff;
        color:#151716;
    }
    .submenu  a:active, .submenu  a:visited{
      display: block;
      color: #fff;
      text-decoration: none;
      z-index: 21;
    }
    .submenu {
      position: absolute;
      display: none;
      width:160px;
      height:250px;
      background:white;
      list-style:none;
    }
    .dropdown:hover > .submenu{
      display: block;

    }
    .submenu>li>a
    {
        display:block;
        width:100%;
        height:42px;
        background:black;
        text-decoration:none;
        line-height:58px;
        padding-left:50px;
        border:1px dashed white;
    }
2个回答

2
问题出在这里:
<li class="dropdown"><li><a href="#">Company</a>

你有两个
  • 标签,请删除其中一个。同时,你忘记在后面添加这个内容:
          </li>
        </ul>
      </li>
    </ul>
    

    这里有一个可用的代码片段:

    * {
      margin: 0px;
      padding: 0px;
    }
    .header_wrap {
      width: 100%;
      height: 160px;
      background: red;
      position: relative;
    }
    .main_wrap {
      width: 100%;
      height: 1475px;
      background: green;
    }
    .footer_wrap {
      width: 100%;
      height: 325px;
      background: aqua;
    }
    .main {
      width: 1000px;
      height: 100%;
      background: blue;
      margin: auto;
    }
    footer {
      width: 1000px;
      height: 100%;
      background: aqua;
      margin: auto;
    }
    .header_top_wrap {
      width: 100%;
      height: 23px;
      background: #ccc;
    }
    .header_bottom_wrap {
      width: 100%;
      height: 40px;
      background: #06F;
      position: absolute;
      bottom: 0px;
      left: 0px;
    }
    .header_top {
      width: 1000px;
      height: 100%;
      background: purple;
      margin: auto;
    }
    .header_bottom {
      width: 1000px;
      height: 100%;
      background: black;
      margin: auto;
    }
    .bottom_menu > li {
      display: inline-block;
    }
    .bottom_menu a
    {
      font-family: Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
      color: #fff;
    
    }
    .bottom_menu > li >a {
      display: block;
      text-decoration: none;
      padding: 0px 30px;
      height: 40px;
      line-height: 35px;
      text-align: center;
    }
    .bottom_menu > li:hover >a
    {
      background:#fff;
      color:#151716;
    }
    .submenu  a:active, .submenu  a:visited{
      display: block;
      color: #fff;
      text-decoration: none;
      z-index: 21;
    }
    .submenu {
      position: absolute;
      display: none;
      width:160px;
      background:white;
      list-style:none;
    }
    .dropdown:hover > .submenu{
      display: block;
    
    }
    .submenu>li>a
    {
      display:block;
      width:100%;
      height:42px;
      background:black;
      text-decoration:none;
      line-height:58px;
      padding-left:50px;
      border:1px dashed white;
    }
    <div class="header_wrap">
      <div class="header_top_wrap">
        <div class="header_top">
        </div>
      </div>
      <!--end of header top wrap -->
      <div class="header_bottom_wrap">
        <div class="header_bottom">
          <ul class="bottom_menu">
            <li class="dropdown"><a href="#">Company</a>
    
              <ul class="submenu">
                <li><a href="#">About us</a></li>
                <li><a href="#">New Realeses</a></li>
                <li><a href="#">Contact us</a></li>
              </ul>
            </li>
            <li class="dropdown"><a  href="#">Products</a>
              <ul class="submenu">
                <li><a href="#">DVR & Kits</a></li>
                <li><a href="#">Seurity Cameras</a></li>
                <li><a href="#">Spy Camreas</a></li>
                <li><a href="#">Wireless & IP Cameras</a></li>
                <li><a href="#">Accessories</a></li>
                <li><a href="#">Mini Video</a></li>
              </ul>
            </li>
            <li><a href="#">Services</a></li>
            <li class="dropdown">
              <a href="#">Support</a>
              <ul class="submenu">
                <li><a href="#">Support Home</a></li>
                <li><a href="#">Warranty</a></li>
                <li class="dropdown">
                  <a href="#">Multimedia</a>
                  <ul class="submenu">
                    <li><a href="#">Video</a></li>
                    <li><a href="#">Podcasts</a></li>
                  </ul>
                </li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
      <!--end of bottom  wrap -->
    </div>
    <!--end of header wrap -->
    <div class="main_wrap">
      <div class="main">
      </div>
      <!--end of main  -->
    </div>
    <!--end of main wrap -->
    <div class="footer_wrap">
      <footer></footer>
    </div>
    <!--end of footer wrap -->


  • 一切都很好,但在下拉列表中单击“公司”和“多媒体”时,白色部分仍然存在,如何删除该部分? - panky
    @panky 给这个CSS:.submenu {height: auto;} - Praveen Kumar Purushothaman
    @panky,请在更新的答案中找到已更正的代码片段。:) - Praveen Kumar Purushothaman
    我明白了,但是兄弟,“多媒体”选项没有显示。 - panky
    @panky,我不确定为什么,但如果你将鼠标移到“多媒体”上,它会起作用。 - Praveen Kumar Purushothaman
    @panky 我很高兴我能帮到你。 - Praveen Kumar Purushothaman

    0

    我明白了,但是点击“服务”时什么也没有出现,而“多媒体”按钮在哪里? - panky
    和服务,你没有任何列表。 - Shimon Brandsdorfer

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接