6

I just want create submenu in my drop down ... but I cant find code to fix this.

HTML CODE :

<nav id='menu'>
  <ul>
    <li><a class='home' href='/'>Home</a></li>
    <li><a class='prett' href='#' title='Menu'>Menu</a>
      <ul class='menus'>
        <li><a class='prett' href='Dropdown 1' title='Dropdown 1'>Dropdown 1 + Sub Menu</a>
          <ul class='submenu'>
            <li><a href="#" title="Sub Menu">Sub Menu</a></li>
          </ul>
        </li>
        <li><a href='#' title='Dropdown 2'>Dropdown 2</a></li>
        <li><a href='#' title='Dropdown 3'>Dropdown 3</a></li>
      </ul>
    </li>
  </ul>
</nav>

CSS CODE :

#menu{background:#343434;color:#eee;height:35px;border-bottom:4px solid #eeeded}
#menu ul,#menu li{margin:0 0;padding:0 0;list-style:none}
#menu ul{height:35px}
#menu li{float:left;display:inline;position:relative;font:bold 12px Arial;text-shadow: 0 -1px 0 #000;border-right: 1px solid #444;border-left: 1px solid #111;text-transform:uppercase}
#menu li:first-child{border-left: none}
#menu a{display:block;line-height:35px;padding:0 14px;text-decoration:none;color:#eee;}
#menu li:hover > a,#menu li a:hover{background:#111}
#menu input{display:none;margin:0 0;padding:0 0;width:80px;height:35px;opacity:0;cursor:pointer}
#menu label{font:bold 30px Arial;display:none;width:35px;height:36px;line-height:36px;text-align:center}
#menu label span{font-size:12px;position:absolute;left:35px}
#menu ul.menus{height:auto;overflow:hidden;width:180px;background:#111;position:absolute;z-index:99;display:none;border:0;}
#menu ul.menus li{display:block;width:100%;font:12px Arial;text-transform:none;}
#menu li:hover ul.menus{display:block}
#menu a.home {background: #c00;}
#menu a.prett{padding:0 27px 0 14px}
#menu a.prett::after{content:"";width:0;height:0;border-width:6px 5px;border-style:solid;border-color:#eee transparent transparent transparent;position:absolute;top:15px;right:9px}
#menu ul.menus a:hover{background:#333;}

Thanks , this site will really help me so much

thepio
  • 6,193
  • 5
  • 35
  • 54
Adam Muiz
  • 381
  • 1
  • 3
  • 17
  • Could you paste your code into a CodePen or something so we can look at it? You're asking us to look through rather a lot of code, and no matter how good you are at CSS you don't know how it'll turn out until you've rendered it in the web browser. – RobertAKARobin Aug 05 '16 at 03:51
  • You need to search yourself for it, See here https://codepen.io/philhoyt/pen/ujHzd – Vishal Panara Aug 05 '16 at 04:07
  • Sorry Im newbie here http://codepen.io/aziu/pen/NAOawJ This , please Help me ... thanks – Adam Muiz Aug 05 '16 at 06:24

1 Answers1

19

I'm not quite sure what kind of result are you expecting but one way to do this is to add a class to the submenu li and watch when it's hovered, after which you show the submenu. Like this:

#menu {
  background: #343434;
  color: #eee;
  height: 35px;
  border-bottom: 4px solid #eeeded
}

#menu ul,
#menu li {
  margin: 0 0;
  padding: 0 0;
  list-style: none
}

#menu ul {
  height: 35px
}

#menu li {
  float: left;
  display: inline;
  position: relative;
  font: bold 12px Arial;
  text-shadow: 0 -1px 0 #000;
  border-right: 1px solid #444;
  border-left: 1px solid #111;
  text-transform: uppercase
}

#menu li:first-child {
  border-left: none
}

#menu a {
  display: block;
  line-height: 35px;
  padding: 0 14px;
  text-decoration: none;
  color: #eee;
}

#menu li:hover > a,
#menu li a:hover {
  background: #111
}

#menu input {
  display: none;
  margin: 0 0;
  padding: 0 0;
  width: 80px;
  height: 35px;
  opacity: 0;
  cursor: pointer
}

#menu label {
  font: bold 30px Arial;
  display: none;
  width: 35px;
  height: 36px;
  line-height: 36px;
  text-align: center
}

#menu label span {
  font-size: 12px;
  position: absolute;
  left: 35px
}

#menu ul.menus {
  height: auto;
  width: 180px;
  background: #111;
  position: absolute;
  z-index: 99;
  display: none;
  border: 0;
}

#menu ul.menus li {
  display: block;
  width: 100%;
  font: 12px Arial;
  text-transform: none;
}

#menu li:hover ul.menus {
  display: block
}

#menu a.home {
  background: #c00;
}

#menu a.prett {
  padding: 0 27px 0 14px
}

#menu a.prett::after {
  content: "";
  width: 0;
  height: 0;
  border-width: 6px 5px;
  border-style: solid;
  border-color: #eee transparent transparent transparent;
  position: absolute;
  top: 15px;
  right: 9px
}

#menu ul.menus a:hover {
  background: #333;
}

#menu ul.menus .submenu {
  display: none;
  position: absolute;
  left: 180px;
  background: #111;
  top: 0;
  width: 180px;
}

#menu ul.menus .submenu li {
  background: #111;
}

#menu ul.menus .has-submenu:hover .submenu {
  display: block;
}
<nav>
  <ul id='menu'>
    <li><a class='home' href='/'>Home</a></li>
    <li><a class='prett' href='#' title='Menu'>Menu</a>
      <ul class='menus'>
        <li class='has-submenu'><a class='prett' href='Dropdown 1' title='Dropdown 1'>Dropdown 1 + Sub Menu</a>
          <ul class='submenu'>
            <li><a href="#" title="Sub Menu">Sub Menu</a></li>
            <li><a href="#" title="Sub Menu">Sub Menu 2</a></li>
            <li><a href="#" title="Sub Menu">Sub Menu 3</a></li>
          </ul>
        </li>
        <li><a href='#' title='Dropdown 2'>Dropdown 2</a></li>
        <li><a href='#' title='Dropdown 3'>Dropdown 3</a></li>
      </ul>
    </li>
  </ul>
</nav>

EDIT:

With Javascript and click to open: https://jsfiddle.net/thepio/pn0ym10e/2/

thepio
  • 6,193
  • 5
  • 35
  • 54
  • Thats Help but , I want Sub Menu on Side Path ... Thanks for helping – Adam Muiz Aug 05 '16 at 06:39
  • Thanks , You are Master :D Can you make command if Not Click not Open , If Click open Tanks so Muchhhh !!! – Adam Muiz Aug 05 '16 at 06:58
  • But when I Add More Sub its look Transparat https://2.bp.blogspot.com/-X7HqK7CVCqM/V6Q6LPQBSNI/AAAAAAAAAAo/VHj8NsHHKtg4CM3F2RiWW8gJYbBnga9MwCLcB/s320/HTML%2BCSS%2BDrop%2BDown.jpg – Adam Muiz Aug 05 '16 at 07:03
  • I updated my answer once again to include a background color for the li elements inside submenu. And if you want it to open on click you will need some Javascript. I included an example fiddle also in the answer. – thepio Aug 05 '16 at 07:25
  • Greatt ist really Workk ... Thanksss – Adam Muiz Aug 05 '16 at 07:35
  • Last Aswerr .. but If you want Make menu like sub menu < Click Open Thanksss Much – Adam Muiz Aug 05 '16 at 07:37
  • And how to add that Javascrip in Blogger Template ? – Adam Muiz Aug 05 '16 at 07:37
  • I'm sorry but that needs to be another question if you can't figure it out on your own. I haven't personally used Blogger so I can't tell. But there must be some way of editing the template. Then you just insert the Javascript let's say right before the closing `

    ` tag in your template inside `` tags and that's it.

    – thepio Aug 05 '16 at 07:48
  • Thanks , Here dude http://stackoverflow.com/questions/38784131/function-javascrip-on-menu-css-html – Adam Muiz Aug 05 '16 at 08:00
  • 1
    Nice example, it helps me a lot. – Shyam Narayan May 25 '20 at 09:14