how to create sub menu in left side bar - html

i am new to HTML and i need to put some sub menus in my side bar.. just like a dropdown but it opens on the right side. and how can i put links on it. thanks
html
<ul>
<li></br>
<a class="active" href="?">HOME</a>
</li>
<li></br>
Manage Users ----> needs the dropdown here
</li>
<li></br>
Manage Employees----> needs the dropdown here
</li>
<li></br>
Search
</li>
<li></br>
Log-Out
</li>
</ul>
here is my css.
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 15%;
background-color: #f1f1f1;
position: fixed;
height: 100%;
overflow: auto;
}
li a {
display: block;
color: #000;
padding: 8px 0 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
...................................................................

<ul>
<li></br>
<a class="active" href="?">HOME</a>
</li>
<li></br>
Manage Users ----> needs the dropdown here
</li>
<li></br>
Manage Employees---->
<ul>
<li> You put the sublists here</li>
<li> Many has you need</li>
</ul>
</li>
<li></br>
Search
</li>
<li></br>
Log-Out
</li>

You don't need the </br> (correct would be <br/>, or <br>for HTML5). I tried to make a simple solution with jQuery. where you simply display or not the content you want.
Hope it is what you were looking for.
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
/*width: 15%;*/
background-color: #f1f1f1;
/*position: fixed;*/
height: 100%;
overflow: auto;
}
li a {
display: block;
color: #000;
padding: 8px 0 8px 16px;
text-decoration: none;
}
li a.active {
background-color: #4CAF50;
color: white;
}
li a:hover:not(.active) {
background-color: #555;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>
<a class="active" href="#">HOME</a>
</li>
<li>
Manage Users
<ul id="contentUsers" style="display: none;">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>
Manage Employees
<ul id="contentEmployees" style="display: none;">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</li>
<li>
Search
</li>
<li>
Log-Out
</li>
</ul>

Related

nested dropdown menu

I am trying to make a nested menu in my nav header. Under Reports there should be two menu items Global Shop and Ndustrios. Then if I hover over either of them there should be more items to show. Currently what happens under Reports is all of the options below it show up when hovered. so it reads: Global Shop, Inventory, Sales Orders, etc.. but Ndustrios doesn't appear.
Here is what I have tried:
#nav_ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1D3567;
text-align: center;
}
li {
display: inline-block;
}
li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 24px 16px;
text-decoration: none;
}
.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #1D3567;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: White;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content ul {
display: none;
position: absolute;
left: 100%;
top: 75;
}
.dropdown-content:hover ul {
display: block;
}
<nav>
<ul id="nav_ul">
<li class="dropdown">
Reports
<div class="dropdown-content">
Global Shop
<div class="dropdown-content">
Inventory
Sales Orders
Quotes
Work Orders
Part Where Used
</div>
Ndustrios
</div>
</li>
</ul>
<nav>
I found the below code and modified it to reflect my needs. Nested drop downs working perfectly
.parent {display: block;position: relative;float: left;line-height:30px;background-color: #1D3567;}
.parent a{margin: 10px;color: #FFFFFF;text-decoration: none;}
.parent:hover > ul {display:block;position:absolute;}
.child {display: none;}
.child li {background-color: #1D3567;line-height: 30px;border-bottom:#CCC 1px solid;border-right:#CCC 1px solid; width:100%;}
.child li a{color: #FFFFFF;}
ul{list-style-type: none;margin: 0;padding: 0px; min-width:15em;}
ul ul ul{left: 100%;top: 0;margin-left:1px;}
li:hover {background-color: #95B4CA;}
.parent li:hover {background-color: #95B4CA;}
<ul id="nav_ul">
<li class="parent">Home</li>
<li class="parent">Outlook Web</li>
<li class="parent">Production
<ul class="child">
<li class="parent">South</li>
<li class="parent">Enclosure Systems</li>
<li class="parent">South</li>
<li class="parent">Factory Andon</li>
<li class="parent">Web Docs</li>
</ul>
</li>
<li class="parent">IT
<ul class="child">
<li>Knowledge Base</li>
<li>Submit a Ticket</li>
<li class="parent">Archived Links</li>
</ul>
</li>
<li class="parent">Office Directories
<ul class="child">
<li>Hennig</li>
<li>AME</li>
</ul>
</li>
<li class="parent">Hennig Parts</li>
<li class="parent">Factory Andon</li>
<li class="parent">Business Cards</li>
<li class="parent">Reports
<ul class="child">
<li class="parent">Global Shop<span class="expand">»</span>
<ul class="child">
<li>Inventory Report</li>
<li>Sales Report</li>
<li>Quotes Report</li>
<li>Work Order Report</li>
<li>Part Where Used Report</li>
</ul>
</li>
<li class="parent">Ndustrios<span class="expand">»</span>
</li>
</ul>
</li>
You will need to do some restructuring to your HTML and use another list inside your li to contain more links. You will still be left with a pretty serious issue though. If you no longer hover the submenu item and the list gets shorter and then you are no longer hovering anything. For example: hover over reports then global shop and try to hover over Ndustrios. You cannot do it because once you leave the drop down sub <li> the list will shrink leaving you with nothing. You have two options. 1. Place Ndustrios above the dropdown or 2. Make the dropdowns appear on click instead of on hover
#nav_ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #1D3567;
text-align: center;
}
li a,
.dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 24px 16px;
text-decoration: none;
}
.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #1D3567;
min-width: 160px;
z-index: 1;
list-style: none;
}
.dropdown-content a {
color: White;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-sub-list{
display: none;
list-style: none;
margin: 0;
}
.dropdown:hover > .dropdown-content {
display: block;
}
.dropdown-sub:hover > .dropdown-sub-list {
display: block;
}
<nav>
<ul id="nav_ul">
<li class="dropdown">
Reports
<ul class="dropdown-content">
<li class="dropdown-sub">
Global Shop
<ul class="dropdown-sub-list">
<li>Inventory</li>
<li>Sales Orders</li>
<li>Quotes</li>
<li>Work Orders</li>
<li>Part Where Used</li>
</ul>
</li>
<li>Ndustrios</li>
</ul>
</li>
</ul>
</nav>
If you are dead set on using dropdowns inside of dropdowns here is a simple example of a hover click dropdown combo. You can also make the top level dropdown clickable if you would like using this method.
const dropdownBtns = document.querySelectorAll(".dropdown-button");
const dropdownItem = document.querySelectorAll(".dropdown-item");
const subDropdown = document.querySelectorAll(".sub-dropdown");
const handleClick = (event) => {
const targetBtn = event.target;
const ariaExpanded = targetBtn.getAttribute("aria-expanded");
const ariaControls = targetBtn.getAttribute("aria-controls");
const controlledAria = document.getElementById(ariaControls);
if(ariaExpanded === "false") {
controlledAria.classList.add("active");
controlledAria.setAttribute("aria-hidden", "false");
targetBtn.setAttribute("aria-expanded", "true");
} else if (ariaExpanded === "true") {
controlledAria.classList.remove("active");
controlledAria.setAttribute("aria-hidden", "true");
targetBtn.setAttribute("aria-expanded", "false");
}
}
const handleLeave = () => {
dropdownBtns.forEach(button => button.setAttribute("aria-expanded", "false"));
subDropdown.forEach(ul => {
ul.classList.remove("active");
ul.setAttribute("aria-hidden", "true");
})
}
dropdownItem.forEach(item => item.addEventListener("mouseleave", handleLeave));
dropdownBtns.forEach(button => button.addEventListener("click", handleClick));
ul {
list-style: none;
padding: 0;
}
button {
background: transparent;
border: none;
width: 100%;
font-family: inherit;
font-size: inherit;
cursor: pointer;
}
a, button {
display: block;
padding: 10px;
border-bottom: 1px solid #ccc;
text-align: center;
}
a {
text-decoration: none;
color: inherit;
}
.dropdown {
display: none;
}
.dropdown-item:hover .dropdown {
display: block;
}
.sub-dropdown {
display: none;
}
.sub-dropdown.active {
display: block;
}
<ul>
<li class="dropdown-item">
hover item
<ul class="dropdown">
<li>
<button class="dropdown-button" aria-controls="dropdown1" aria-expanded="false">click item</button>
<ul id="dropdown1" class="sub-dropdown" aria-hidden="true">
<li>sub link</li>
<li>sub link</li>
<li>sub link</li>
<li>sub link</li>
<li>sub link</li>
</ul>
</li>
<li>standard link</li>
</ul>
</li>
<ul>

Gap Between dropdown menu and sub menu

I'd like for the menu sub menu to show 10 pixels underneath the menu, i can achieve that using margin-top on the ul, but then i cant move my mouse down to the sub menu because there is a gap. There are posts very similar to this but i could't extract an answer from them. Like this one
Space between menu and drop down menu
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
margin-top: 18px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2 long lel</li>
<li>Sub Menu 3 really bare long mad</li>
<li>Sub Menu 4 dvg</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg</li>
<li>sdfg</li>
<li>sdfgsdfgsdfgsdfg</li>
<li>sdfgsdfgsdfgsdfgsdfg</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf</li>
<li>sfdgsdfgsdfgl</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1</li>
<li>Sub Deep 2</li>
<li>Sub Deep 3</li>
<li>Sub Deep 4</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages</li>
<li class="point">light version</li>
</ul>
UPDATE:
Now that you gave the reference, the hover menu is not actually distant from the li itself, but it is positioned right below it. On the example site the li has a height bigger than the text within and has position: relative; on it.
The dropdown is absolute positioned right below this bigger <li> element with a top: 100%; that way it is distant from the text that triggers the dropdown.
Check the updated Snippet bellow with an updated solution.
Margins are not 'hoverable', and therefore the hover selector is not triggered. One way to keep it distant whilst 'hoverable' is to use padding instead of margins.
So you could change your .lmao li ul, although I wouldn't advise adding style to tags as a CSS best practice, I usually adopt a CSS naming convention such as BEM, SMACSS, among others.
/* Reset the ul style */
ul {
list-style: none;
padding: 0;
margin: 0;
}
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao {
width: 100%;
text-align: center;
}
.lmao li {
display: inline-block;
background-color: white;
padding: 15px;
position: relative;
padding: 20px;
}
.lmao li a {
text-decoration: none;
color: black;
}
.lmao li a:hover {
text-decoration: none;
color: #f38763;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
top: 100%;
min-width: 200px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1
</li>
<li>Sub Menu 2 long lel
</li>
<li>Sub Menu 3 really bare long mad
</li>
<li>Sub Menu 4 dvg
</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li>sdfg
</li>
<li>sdfgsdfgsdfgsdfg
</li>
<li>sdfgsdfgsdfgsdfgsdfg
</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf
</li>
<li>sfdgsdfgsdfgl
</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1
</li>
<li>Sub Deep 2
</li>
<li>Sub Deep 3
</li>
<li>Sub Deep 4
</li>
</ul>
</li>
<li>Deep Menu 2
</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages
</li>
<li class="point">light version
</li>
</ul>
body {
background-color: #cac3bc
}
nav {
float: left;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background-color: #fff;
margin-top: 10px;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-table;
margin-right: -80px;
}
nav ul li {
float: left;
}
nav ul li:hover {
border-bottom: 5px solid #f5aa65;
color: #fff;
}
nav ul li a:hover {
color: #000;
}
nav ul li a {
display: block;
padding: 15px 15px;
font-family: 'PT Sans', sans-serif;
color: #000;
text-decoration: none;
}
nav ul ul {
background-color:#fff;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #000;
}
nav ul ul:before {
content: "";
display: block;
height: 20px;
position: absolute;
top: -20px;
width: 100%;
}
<body>
<nav>
<ul>
<li>One
<ul>
<li>A</li>
<li>B
</ul>
</li>
<li>Two
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</li>
<li>Three
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
<li>Four</li>
</ul>
</nav>
</body>

Menu different in chrome browser

for some reason my menu bar (its fixed) is in 2 lines in chrome browser and normal in all other browsers. Any idea why or how to fix it? I tried to figure it out but i didnt fix it. Is it a problem with browser default block height or what? I need to make it work on chrome and on all other browsers too.
JsFiddle: https://jsfiddle.net/wkupr9L6/1/
HTML:
<script>
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 65) {
$("nav").css("opacity", "0.2");
}
else {
$("nav").css("opacity", "1");
}
});
</script>
</head>
<body>
<!--MENU BAR!-->
<nav class="navig">
<span class="nadpis"> RPO </span>
<ul class="nav">
<li class="prve">Dátumy
<ul>
<li>1-7/7/2016
<ul>
<li>1/7/2016</li>
<li>2/7/2016</li>
<li>3/7/2016</li>
<li>4/7/2016</li>
<li>5/7/2016</li>
<li>6/7/2016</li>
<li>7/7/2016</li>
</ul>
</li>
<li>8-14/7/2016
<ul>
<li>8/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
<li>15-21/7/2016
<ul>
<li>15/7/2016</li>
<li>9/7/2016</li>
<li>10/7/2016</li>
<li>11/7/2016</li>
<li>12/7/2016</li>
<li>13/7/2016</li>
<li>14/7/2016</li>
</ul>
</li>
</ul>
</li>
<li class="druhe">&#9776
<ul>
<li> FLV
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> FLC
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> QUA
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> HFX
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> PDT
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul></li>
<li> RSH
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> BUR
<ul>
<li>meno1 </li>
<li>meno2 </li>
<li>meno3 </li>
<li>meno4 </li>
<li>meno5 </li>
</ul>
</li>
<li> SUHRN </li>
<li> INCI </li>
<li> JIRA </li>
<li> CHGT </li>
<li> TASK </li>
<li> VRS </li>
</div>
</ul>
</li>
</ul>
</nav>
CSS:
body, nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav {
display: inline-block;
position: fixed;
width: 100%;
text-align: center;
background-color: #111;
vertical-align: top;
top: -1px;
opacity: 1;
transition: 0.3s;
}
nav:hover {
opacity: 1!important;
background-color: #111;
transition: 0.3s;
}
.nav a {
display: block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.7em 1.7em;
text-transform: uppercase;
font-size: 85%;
letter-spacing: 3px;
position: relative;
}
.nav{
vertical-align: top;
display: inline-block;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
margin-right: 1px;
}
.nav li:hover > a {
transition: 0.3s;
background-color:#3a3939;
color: #40d23b;
}
.nav ul {
position: absolute;
white-space: nowrap;
z-index: 1;
left: -99999em;
background-color: #000;
border: 2px solid #81D4FA;
border-top: none;
}
.nav > li:hover > ul {
left: auto;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
top:-1px;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
right: 10px;
}
.prve{
max-width:125px;
min-width: 90px;
border: 2px solid #81D4FA;
border-bottom: none;
border-top: none;
}
.druhe {
max-width: 14px;
min-width: 110px;
border-right: 2px solid #81D4FA;
}
span {
float:left;
margin-left: 3px;
}
span a{
text-decoration: none;
color:#2670CF;
background-color:#111;
font-family: 'Helvetica Neue', sans-serif;
font-size: 30px;
font-weight: bold;
}
Thanks for help
This doesn't seem like a browser issue. You have .nav set to display: inline-block; but nothing on the two inner <li> elements to force them onto the same line.
I added this:
.nav > li {
display: inline-block;
}
And it works for me in Chrome. See here:
https://jsfiddle.net/tobyl/wkupr9L6/6/

Nested li elements not aligning properly

I am able to display all the nested li's inline. What I don't understand is why there is a gap between About and Our Team li elements. I have already tried setting the margin and padding of both ul and li elements to 0.
<div ng-show = "buttonDisplay" id = "buttonDisplayContent">
<ul>
<li> Home </li>
<li class = "subLi"> About </li>
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services </li>
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
CSS
#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul a {
text-decoration: none;
color: #000;
font-size: 25px;
font-weight: bold;
}
#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 15px;
font-weight: bold;
}
.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}
.nested {
margin-left: 0;
}
.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}
#buttonDisplayContent ul li:hover {
background-color: black;
}
UPDATE
Thanks for all your help. I changed my HTML and CSS as follows. Li elements are still not aligning as desired. Here is a fiddle: https://jsfiddle.net/qvq87ke1/2/
HTML
<div ng-show = "buttonDisplay" id = "buttonDisplayContent" >
<ul>
<li> Home </li>
<li class = "subLi">About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
</li>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
CSS
#buttonDisplayContent {
background-color: #141516;
width: 100%;
margin-top: 9%;
text-align: center;
position: absolute;
opacity: 0.9;
}
#buttonDisplayContent ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul ul {
list-style-type: none;
padding: 0;
}
#buttonDisplayContent ul a {
text-decoration: none;
color: #fff;
font-size: 50px;
font-weight: bold;
}
#buttonDisplayContent ul ul a {
text-decoration: none;
color: lightgray;
font-size: 40px;
font-weight: bold;
}
.subLi {
float: left;
margin: 0;
padding: 0;
list-style-type: none;
}
.nested {
float: right;
margin-left: 0;
}
.nested li {
display: inline-block;
padding-bottom: 6px;
padding-right: 1%;
padding-left: 1%;
padding-top: 8px;
}
#buttonDisplayContent ul li:hover {
background-color: black;
}
Your markup looks like it is incorrect. When nesting un-ordered or ordered lists they should be contained withing the li they will be creating a sub list for.
Like this:
<ul>
<li>One</li>
<li>Two
<ul>
<li>One - Sub Two</li>
<li>Two - Sub Two</li>
</ul>
</li>
<li>Three</li>
</ul>
You are adding your ul between the li:
<li class="subLi">About</li>
<ul class="nested">
<li>Our Team</li>
<li>Our efforts</li>
</ul>
<li class="nextToNested">Blog</li>
Updated answer based on updated question..
Try setting display:inside; on your nested <ul> and put your nested <ul> inside of the <li>
P.S. A screenshot or a fiddle (or at least your plain CSS) would be really helpful..
You should post a JSFiddle with your code, that would be easier to help you.
Otherwise, as a good practice, the UL nested nested should be in the previous LI (which should it parent so).
<li class = "subLi">
About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
Maybe this is where the problem comes from.
If it can helps you:
Proper way to make HTML nested list?
Good Luck'
It's possible there is some padding/margin on the "a" element as well from the browser. Best practices is to import a reset.css file at the beginning of your project to clear all browser-applied CSS and style it on your own or using a framework.
I figured it out. I was floating the li elements unnecessarily.
<div ng-show = "buttonDisplay" id = "buttonDisplayContent" >
<ul>
<li> Home </li>
<li class = "subLi">About
<ul class = "nested">
<li> Our Team </li>
<li> Our efforts </li>
</ul>
</li>
<li class = "nextToNested"> Blog </li>
<li class = "subLi"> Services
<ul class = "nested">
<li> Design </li>
<li> Web </li>
<li> Learn </li>
<li> Invent </li>
</ul>
</li>
<li class = "nextToNested"> Portfolio </li>
<li> Contact </li>
</ul>
</div>
SASS
#buttonDisplayContent
background-color: #141516
width: 100%
margin-top: 9%
text-align: center
position: absolute
opacity: 0.9
#buttonDisplayContent
ul
list-style-type: none
padding: 0
#buttonDisplayContent
ul
ul
list-style-type: none
padding: 0
#buttonDisplayContent
ul
a
text-decoration: none
color: #fff
font-size: 50px
font-weight: bold
#buttonDisplayContent
ul
ul
a
text-decoration: none
color: lightgray
font-size: 40px
font-weight: bold
.subLi
//float: left
margin: 0
padding: 0
list-style-type: none
.nested
//float: right
margin-left: 0
display: inline
.nested
li
display: inline
padding-bottom: 6px
padding-right: 1%
padding-left: 1%
padding-top: 8px
#buttonDisplayContent
ul
li:hover
background-color: black

Building a menu using css html

I need my menu to change color when hovering my mouse over each top menu. The problem is the background color for both Test1 and Sub test1 changes as I hover my mouse. Is there any way to not change the background color of Sub test1 until I hover the mouse over it? See the code at http://jsfiddle.net/r5YCU/22/
Any help will be appreciated. Thanks.
<div id="navbar">
<ul>
<li class="navbutton"><span><a id="button-1"
href="">Shop</a></span>
</li>
<li class="navbutton"> <span>Test1</span>
<ul>
<li><br/><span>Sub test1
</span>
</li>
</ul>
</li>
<li class="navbutton"><span><a id="button-3"
href="#">Test2</a>
</span>
</li>
<li class="navbutton"><span><a id="button-4"
href="#">Test3</a></span>
</li>
<li class="navbutton"><span><a id="button-5"
href="#">Test4</a></span>
</li>
I'd play with css :hover pseudoclass instead javascript events, something like:
li.navbutton:hover {
background-color:#345808 !important;
}
li.navbutton:hover li {
background-color: #5c8727!important;
}
li.navbutton li:hover {
background-color: #345808!important;
}
The complete code is: http://jsfiddle.net/r5YCU/31/
I've adapted the layout a bit to look as similar as possible to the original menu, but only with css code.
These things are related to style and should be done in css...
CSS
.ul{
list-style: none;
}
#navbar a{
text-decoration: none;
}
#main-ul{
background: yellow;
}
.navmenu{
float: left;
background: deeppink;
width: 60px;
height: 25px;
margin-right: 3px;
text-align: center;
line-height: 25px;
box-shadow: 0 0 2px 3px black;
}
.navmenu:hover{
outline: 1px solid white;
margin-top: 1px;
}
.navmenu:hover > #sub-ul{
display: block;
width: 100px;
background: red;
}
#sub-ul{
margin: 0;
padding: 0;
display: none;
}
.submenu{
margin: 0;
padding: 0;
margin-bottom: 2px;
background: black;
color: white;
}
.submenu:hover{
cursor: pointer;
color: black;
background: #585858;
}
HTML
<div id="navbar">
<ul class="ul" id="main-ul">
<li class="navmenu">Test1</li>
<li class="navmenu">Test2
<ul class="ul" id="sub-ul">
<li class="submenu">Test 1</li>
<li class="submenu">Test 2</li>
<li class="submenu">Test 3</li>
<li class="submenu">Test 4</li>
<li class="submenu">Test 5</li>
<li class="submenu">Test 6</li>
<li class="submenu">Test 7</li>
<li class="submenu">Test 8</li>
</ul>
</li>
<li class="navmenu">Test3</li>
<li class="navmenu">Test4</li>
<li class="navmenu">Test5</li>
<li class="navmenu">Test6</li>
<li class="navmenu">Test7</li>
</ul>
</div>