html - Dropdown menu items not stacking vertically -
hi have website dropdown menu , reason items stack horizontally. html this
<li id="menuitem">a</li> <ul id="dropdown"> <li id="dropdownelement">b</li> </ul>
and css sets ul hidden unless hover. , li elements relative
there few problems implementation.
you can test demo , see if desired behaviour.
you should set ul ul
elements positioned absolute
, , ul li
relative
inline-block
display prop.
then, change #navbar ul li:hover ul
this:
#navbar ul li:hover ul { display: block; position: absolute; left: 0; padding: 0; }
this sets nested dropdown positioned below parent aligned left.
also, have used #accountdropdownelement
id twice in markup. replaced class in demo because id
s must unique!
here's full code:
#navbar ul { position: relative; display: inline-table; list-style-type: none; width: 965px; } #navbar ul:after { content: ""; clear: both; display: block; } #navbar ul ul { display: none; position: absolute; top: 66px; left: 0; padding: 0; } #navbar ul ul li { float: none; position: relative; } #navbar ul li { float: left; padding: 0 10px; border-radius: 25px; } #navbar ul li:hover > { border: 1px rgb(204, 255, 102) solid; background-color: rgb(204, 255, 102); box-shadow: none; } #navbar ul li:hover ul { display: block; position: absolute; left: 0; padding: 0; } #navbar ul li:hover ul li { float: none; } #navbar ul li { border-radius: 25px; border: 1px rgb(57, 232, 38) solid; background-color: rgb(57, 232, 38); box-shadow: 0px 3px 3px rgba(0,0,0,0.5); color: white; display: block; float: left; font-family: "micross"; font-size: 30px; padding: 15px; text-decoration: none; } #navbar ul li a:hover { border: 1px rgb(204, 255, 102) solid; background-color: rgb(204, 255, 102); box-shadow: none; } #accountbutton:hover { cursor: pointer; } #accountdropdownimage { float: left; } .accountdropdownelement { width: 100px; background-color: rgb(57, 232, 38); color: white; font-size: 20px; margin: 0; padding-left: 20px; padding-right: 20px; padding-top: 10px; padding-bottom: 10px; }
<link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/navbar.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <div id="navbar"> <ul id="navbarlist"> <li id="homebutton"><a href="home.php">home</a></li> <li id="blogbutton"><a href="blog.php">blog</a></li> <li id="downloadsbutton"><a href="downloads.php">downloads</a></li> <li id="managerbutton"><a href="manager.php">manager</a></li> <li id="accountbutton"><a id='accountabutton' href='manager.php'>luke</a> <ul id='dropdownlist'> <li><p class='accountdropdownelement'>logout</p></li> <li><p class='accountdropdownelement'>login</p></li> </ul> </li> </ul> </div>
Comments
Post a Comment