Creating a Dropdown Menu with CSS Not Working - html

The dropdown menu (sub) does not appear right below the element it is supposed to when I hover on the navbar. How can I get it to appear below it instead of to the right of it? Also, how can I get the extra spacing on the left side of each menu to disappear? I tried setting the padding to 0, but that did not change anything.
a {
text-decoration: none;
color: #000;
}
.navbar {
background-color: #f2f2f2;
position: fixed;
top: 0;
width: 100%;
text-align: center;
font-family: "Raleway";
font-size: 93%;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
left: 0;
}
.navbar > li{
display:inline-block;
}
.navbar li {
list-style-type: none;
padding-left: none;
}
.navbar a {
float: center;
display:inline-block;
color: #000000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.navbar a:hover {
background-color: #ddd;
}
.navbar li:hover ul.sub {
display: inline-block;
}
.dropdown {
position: relative;
display: inline-block;
}
ul.sub {
padding-left: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
ul.sub a {
color: #000000;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
<ul class = "navbar">
<!--add dropdown menu links for everything except collaboration-->
<li class = "dropdown">
<li>About FRES(H)
<ul class = "sub">
<li>Safety</li>
<li>Sense</li>
<li>Express</li>
<li>Keep Fresh</li>
<li>Notebook</li>
<li>Interlab</li>
<li>Protocols</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Models
<ul class = "sub">
<li>Protein Modelling Etnr1</li>
<li>Protein Modelling Etnr2</li>
<li>Internal Cellular Model</li>
<li>Macroscopic Diffusion Model</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Technology
<ul class = "sub">
<li>Primer Design App</li>
<li>SmartPhone App</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Human-Centered Design
<ul class = "sub">
<li>Integrated Human Practices</li>
<li>Outreach</li>
<li>Theory of Knowledge</li>
</ul>
</li>
</li>
<li>Engagement</li>
<li class = "dropdown">
<li>Meet the Team
<ul class = "sub">
<li>About Us</li>
<li>Attributions</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Awards
<ul class = "sub">
<li>Parts</li>
<li>Medals</li>
</ul>
</li>
</li>
</ul>

You were almost there! You just added the :hover to the wrong div.
Make the following changes:
display:none to ul.sub and .navbar li:hover ul.sub instead of .navbar:hover ul.sub
UPDATE: to centre the ul.sub, use display: block. To remove padding, assign value of 0, instead of 'none'. See example below:
a {
text-decoration: none;
color: #000;
}
.navbar {
background-color: #f2f2f2;
position: fixed;
top: 0;
width: 100%;
text-align: center;
font-family: "Raleway";
font-size: 93%;
border-width:1px 0;
list-style:none;
margin:0;
padding:0;
left: 0;
}
.navbar > li{
display:inline-block;
}
.navbar li {
list-style-type: none;
padding-left: none;
}
.navbar a {
float: center;
display:inline-block;
color: #000000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.navbar a:hover {
background-color: #ddd;
}
.navbar li:hover ul.sub {
display: block;
}
.dropdown {
position: relative;
display: inline-block;
}
ul.sub {
padding-left: 0;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
display:none;
}
ul.sub a {
color: #000000;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
<ul class = "navbar">
<!--add dropdown menu links for everything except collaboration-->
<li class = "dropdown">
<li>About FRES(H)
<ul class = "sub">
<li>Safety</li>
<li>Sense</li>
<li>Express</li>
<li>Keep Fresh</li>
<li>Notebook</li>
<li>Interlab</li>
<li>Protocols</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Models
<ul class = "sub">
<li>Protein Modelling Etnr1</li>
<li>Protein Modelling Etnr2</li>
<li>Internal Cellular Model</li>
<li>Macroscopic Diffusion Model</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Technology
<ul class = "sub">
<li>Primer Design App</li>
<li>SmartPhone App</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Human-Centered Design
<ul class = "sub">
<li>Integrated Human Practices</li>
<li>Outreach</li>
<li>Theory of Knowledge</li>
</ul>
</li>
</li>
<li>Engagement</li>
<li class = "dropdown">
<li>Meet the Team
<ul class = "sub">
<li>About Us</li>
<li>Attributions</li>
</ul>
</li>
</li>
<li class = "dropdown">
<li>Awards
<ul class = "sub">
<li>Parts</li>
<li>Medals</li>
</ul>
</li>
</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>

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

Please help me to fix the error in this menu code

I have learnt CSS online and I am new to web designing. Need some expert opinion here, I may have written something wrong or stupid. Please forgive that as I am a beginner.
Here are my CSS and HTML codes:
#menu {
float: left;
width: 1000px;
height: 30px;
background-color:#0066FF;
border-bottom: 1px solid #333;``
}
#menu ul {
float: left;
width: 1000px;
margin: 0;
padding: 7px 0 0 0;
list-style: none;
}
#menu ul li{
display:inline;
}
li ul {display: none;}
li:hover ul {display: block; position:relative;}
li:hover li a{background: #0066FF;}
#menu ul li a{
float: left;
padding: 0 20px;
font-size: 12px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #FFFFFF;
}
#menu li a:hover, #menu li .current{
color: #FFFF00;
}
#menu ul li:hover ul{
width: 150px;
white-space: nowrap
height: 10px;
text-align: center;
background:#0066FF;
}
<div id="menu">
<ul>
<li>Home</li>
<li>Quran
<ul>
<li>Translation</li>
<li>Tajweed</li>
<li>Tafseer</li>
<li>Qoutes</li>
</ul>
</li>
<li>Ahadees
<ul>
<li>Sahih Al-Bukhari</li>
<li>Sahih Muslim</li>
<li> Sunan Abu-Dawud</li>
<li>al-Tirmidhi</li>
<li>al-Nasa'i</li>
<li>Ibn Maja </li>
</ul></li>
<li>Wazaif
<ul>
<li>Allah's help</li>
<li>Rizzaq</li>
<li>Aulaad</li>
<li>Marriage</li>
</ul></li>
<li>Rights & Duties
<ul>
<li>As Parents</li>
<li>As Husband</li>
<li>As Wife</li>
<li>As Son</li>
<li>As Daughter</li>
</ul></li>
<li>Videos
<ul>
<li>Molana Tariq Jameel</li>
<li>Dr Zakir Naik</li>
<li>Dr Farhat Hashmi</li>
<li>Naat videos</li>
</ul></li>
<li>Quran & Science</li>
<li>Library
<ul>
<li>Masnoon Duain</li>
<li>Tib-e-Nabvi</li>
<li>Tafseer</li>
<li>Islamic comerace</li>
</ul></li>
<li>FAQs</li>
<li>Blogs</li>
<li>Contacts</li>
</ul>
</div>
It looks like the problem is that you haven't positioned the sub-menus properly.
Because the sub-menu have not been given position:absolute they remain in the documents flow and so disturb other elements when shown.
Adding position:absolute removes them from the flow and solves the problem.
In order to be positioned according to the parent li, that li needs to be a block (hence display:inline-block)(you could float the li too if that's your choice) and be given position:relative.
Here's a suggestion that should help you along the way.
#menu ul li {
display:inline-block;
position: relative;
}
li ul {
display: none;
position: absolute;
top:100%;
left:0;
}
li:hover ul {
display: block;
}
JSfiddle Demo
#menu {
float: left;
width: 1000px;
height: 30px;
background-color: #0066FF;
border-bottom: 1px solid #333;
``
}
#menu ul {
float: left;
width: 1000px;
margin: 0;
padding: 7px 0 0 0;
list-style: none;
}
#menu ul li {
display: inline-block;
position: relative;
}
li ul {
display: none;
position: absolute;
top: 100%;
left: 0;
}
li:hover ul {
display: block;
}
li:hover li a {
background: #0066FF;
}
#menu ul li a {
float: left;
padding: 0 20px;
font-size: 12px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #FFFFFF;
}
#menu li a:hover,
#menu li .current {
color: #FFFF00;
}
#menu ul li:hover ul {
width: 150px;
white-space: nowrap height: 10px;
text-align: center;
background: #0066FF;
}
<div id="menu">
<ul>
<li>Home
</li>
<li>Quran
<ul>
<li>Translation
</li>
<li>Tajweed
</li>
<li>Tafseer
</li>
<li>Qoutes
</li>
</ul>
</li>
<li>Ahadees
<ul>
<li>Sahih Al-Bukhari
</li>
<li>Sahih Muslim
</li>
<li> Sunan Abu-Dawud
</li>
<li>al-Tirmidhi
</li>
<li>al-Nasa'i
</li>
<li>Ibn Maja
</li>
</ul>
</li>
<li>Wazaif
<ul>
<li>Allah's help
</li>
<li>Rizzaq
</li>
<li>Aulaad
</li>
<li>Marriage
</li>
</ul>
</li>
<li>Rights & Duties
<ul>
<li>As Parents
</li>
<li>As Husband
</li>
<li>As Wife
</li>
<li>As Son
</li>
<li>As Daughter
</li>
</ul>
</li>
<li>Videos
<ul>
<li>Molana Tariq Jameel
</li>
<li>Dr Zakir Naik
</li>
<li>Dr Farhat Hashmi
</li>
<li>Naat videos
</li>
</ul>
</li>
<li>Quran & Science
</li>
<li>Library
<ul>
<li>Masnoon Duain
</li>
<li>Tib-e-Nabvi
</li>
<li>Tafseer
</li>
<li>Islamic comerace
</li>
</ul>
</li>
<li>FAQs
</li>
<li>Blogs
</li>
<li>Contacts
</li>
</ul>
</div>

white space in navigation

I want to make this navigation that it looks like in tiled format. But here some white spaces coming at the end of the one row. Is it possible to make it form like a border surrounded by navigation & inside it navigation looks like proper tiles instead of some white space..
My Code..
.nav {
width: 960px;
margin: 50px auto;
border: 1px solid #06c;
display: table
}
.nav ul {
padding: 0;
margin: 0
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: Swis721 Cn BT;
font-weight: bold;
display: block
}
.nav ul li a {
text-decoration: none;
color: #06C;
padding: 10px 20px 10px 12px;
display: block
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li>EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>INFRASTRUCTURE & REAL ESTATE
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li>MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li>THEME PARK
</li>
</ul>
</div>
Probably this will work as i have given some special styles (css) to some 'li' however this will not provide 100% output as you want but still effective in such case..
.nav {
width: 970px;
margin: 50px auto;
border:0px solid;
display: table
}
.nav ul {
padding: 0;
margin: 0
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: Swis721 Cn BT;
font-weight: bold;
display: block;
min-width:5%;
width:auto;
text-align:center
}
.nav ul li a {
text-decoration: none;
color: #06C;
padding: 10px 20px 10px 12px;
display: block
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li style="width:25%">EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>THEME PARK
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li style="width:15%">MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li style="width:45%">INFRASTRUCTURE & REAL ESTATE
</li>
</ul>
</div>
Note : Keep in mind the output will be different in such case like change of fonts, or any navigation position change other than it is written now..
you can use this
.nav{
border:0px solid;
}
.nav ul li{
width:25%;/*according to your need you can increase or decrease*/
}
.nav ul {
padding: 0;
margin: 0
}
.nav {
width: 960px;
margin: 50px auto;
border: 1px solid #06c;
display: table;
padding: 0px 0px;
font-size: 100%;
}
.nav ul li {
list-style: none;
float: left;
border: 1px solid #06C;
font-family: sans-serif;
font-weight: bold;
min-width: 7.8%;
width: auto;
font-size: inherit;
text-align: center;
}
.nav ul li a {
text-decoration: none;
color: #06C;
adding: 10px 12px 10px 12px;
display: list-item;
WIDTH: AUTO;
min-width: 100%;
box-sizing: border-box;
}
.nav ul li a:hover {
color: #fff;
background: #06c
}
<div class="nav">
<ul>
<li>ALL
</li>
<li>AGENCY
</li>
<li>AUTOMOBILES
</li>
<li>BANKING
</li>
<li>CONSUMER DURABLE & FMCG
</li>
<li>CONSULTING
</li>
<li>EDUCATIONAL
</li>
<li>FINANCIAL SERVICES
</li>
<li>HOSPITALITY
</li>
<li>INFRASTRUCTURE & REAL ESTATE
</li>
<li>INTERNATIONAL
</li>
<li>IT
</li>
<li>LEGAL
</li>
<li>MANFACTURING
</li>
<li>MARINE
</li>
<li>MEDIA
</li>
<li>OIL & GAS
</li>
<li>ONLINE
</li>
<li>OTHERS
</li>
<li>PHARMA
</li>
<li>RETAIL
</li>
<li>THEME PARK
</li>
</ul>
</div>