简体   繁体   中英

Dropdown menu in custom navigation bar

I'm using a nav bar for my website which I got from an online template. I made some necessary changes in code and made it suitable for my project. But I'm unable to add a drop down menu. How can I add dropdown menu in the main menu.

Here is the code

 html { height: 100%; } * { margin: 0; padding: 0; } body { font: normal .80em 'trebuchet ms', arial, sans-serif; background: #FFF; color: #555; } p { padding: 0 0 20px 0; line-height: 1.7em; } #menubar { width: 880px; height: 46px; } ul#menu { float: right; margin: 0; } ul#menu li { float: left; padding: 0 0 0 9px; list-style: none; margin: 1px 2px 0 0; background: #5A5A5A url(tab.png) no-repeat 0 0; } ul#menu li a { font: normal 100% 'trebuchet ms', sans-serif; display: block; float: left; height: 20px; padding: 6px 35px 5px 28px; text-align: center; color: #FFF; text-decoration: none; background: #5A5A5A url(tab.png) no-repeat 100% 0; } ul#menu li.selected a { height: 20px; padding: 6px 35px 5px 28px; } ul#menu li.selected { margin: 1px 2px 0 0; background: #00C6F0 url(tab_selected.png) no-repeat 0 0; } ul#menu li.selected a, ul#menu li.selected a:hover { background: #00C6F0 url(tab_selected.png) no-repeat 100% 0; color: #FFF; } ul#menu li a:hover { color: #E4EC04; } 
 <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type="text/css" href="post.css"/> </head> <body> <div id="main"> <div id="menubar"> <ul id="menu"> <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on --> <li><a href="#">Home</a></li> <li><a ref="#">Projects</a></li> <li><a href="#">Publications</a></li> <li><a ref="#">News</a></li> <li><a ref="#">Members</a></li> <li><a ref="#">Gallery</a></li> <li><a ref="#">Contact Us</a></li> </ul> </div> </div> </body> </html> 

I followed many online tutorials. But I couldn't display drop down sub menu arrow for above main menu.

CSS:

html{ height: 100%;}

*
{ margin: 0;
  padding: 0;}
body
{ font: normal .80em 'trebuchet ms', arial, sans-serif;
  background: #FFF;
  color: #555;}

nav{
    margin-top:15px
}

nav ul{
    list-style:none;
    position:relative;
    float:left;
    margin:0;
  max-width:700px;
  width:100%;
  background: #5A5A5A url(tab.png) no-repeat 0 0;
  height:50px;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center; 
}

nav ul a{
    display:block;
    color: #fff;
    text-decoration:none;
    font-weight:700;
    font-size:12px;
    line-height:32px;
    padding:0 15px;
    font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif;
  padding:10px;
  border-radius:5px;
  align-self:center;
}

nav ul li{
    position:relative;
    float:left;
    margin:0;
    padding:0;
}

nav ul li.current-menu-item{
    background: gray;
}

nav ul li a:hover{
  color: yellow;
  cursor: pointer;
}

nav ul ul{
    display:none;
    position:absolute;
    top:100%;
    left:0;
  background: #5A5A5A url(tab.png) no-repeat 0 0;
    padding:0
}

nav ul ul li{
    float:none;
    width:200px;
  background: #5a5a5a;
}

nav ul ul a{
    line-height:120%;
    padding:10px 15px
   color: white !important;
}

nav ul ul ul
{
    top:0;
    left:100%
}

nav ul li:hover > ul
{
    display:block
}

/* standard */
body {
  font-family: 'Open Sans';
  font-size:15px
}
a{
  text-decoration:none;
  color:#fff;
}

HTML:

<nav>
  <div>
    <ul>
      <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
      <li ><a  href="#" >Home</a></li>

      <li  ><a  ref="#" >Projects</a></li>
      <li  ><a href="#" >Publications</a></li>
         <li  ><a  ref="#"  >News</a></li>
      <li ><a ref="#" >Members</a></li>
      <li ><a  ref="#" >Gallery</a></li>
      <li ><a ref="#" >Contact Us</a></li>
      <li><a href="#">Dropdown</a>
        <ul>
          <li><a href="#">Dark</a></li>
          <li><a href="#">Basic Light</a></li>
          <li><a href="#">Playful</a></li>
          <li><a href="#">Elegant</a></li>
        </ul>
      </li>
    </ul>
  </div>
</nav>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM