I am trying to make a website with a dropdown menu. After reading several guides and even searching here, The menu keeps doing weird stuff. I tried a lot of things so some lines may become superfluous.
The submenu is not underneath the menu but next to it.
Someone that can help me?
thx in advance
html:
<div id="menu">
<ul>
<li class="current_page_item">Home</li>
<li>Hardware
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul></li>
<li>About Us</li>
<li>sjabloon</li>
<li>Contact Us
</li>
</ul>
</div> <!-- menu -->
Css:
#menu
{
position: absolute;
right: 0;
}
#menu ul
{
display: inline-block;
line-height: 1em;
position: relative; /* naast elkaar*/
right: 0;
top: 2em;
list-style: none;
/*display: inline-table;*/
}
/*
#menu ul: after
{
content: "";
clear: both;
display: inline-block;
}*/
#Menu ul ul {
display: none;
}
/*
#Menu ul li:hover > ul
{
display: inline-block;
}
*/
#menu ul li
{
float: left; /* op een lijn */
margin-left: 0.50em;
padding: 1em 1.5em;
letter-spacing: 0.20em;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
color: #OOC;
outline: 0;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul li a /*#menu ul li span*/
{
display: inline-block
margin-left: 0.50em;
letter-spacing: 0.20em;
text-decoration: none; /* geen onderlijning*/
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #OOC;
}
#menu ul ul /* submenu*/
{
background: #00F;
top: 100%;
padding: 0;
position: absolute;
visibility: hidden;
}
#menu ul:hover ul
{
visibility:visible;
}
#menu ul ul li
{
float: none; /*onder mekaar */
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
position: relative;
color: #FFF;
}
This will help you:
HTML
<div id="menu">
<ul>
<li class="current_page_item">Home
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>Hardware
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>About Us
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>sjabloon
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>Hardware2</li>
<li>Hardware3</li>
</ul>
</li>
</ul>
</div>
StyleSheet
#menu {
position: absolute;
right: 0;
}
#menu ul {
display: inline-block;
line-height: 1em;
position: relative;
/*right: 0;*/
top: 2em;
list-style: none;
}
#menu ul li {
float: left;
padding: 1em 1.5em;
letter-spacing: 0.20em;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
color: #00C;
outline: 0;
}
#menu ul li a {
display: inline-block;
margin-left: 0.50em;
letter-spacing: 0.20em;
text-decoration: none;
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #00c;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul:hover ul {
visibility: visible;
}
#menu ul ul {
/*display: none;*/
background: #00F;
top: 100%;
padding: 0;
position: absolute;
visibility: hidden;
}
#menu ul ul li {
float: none;
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
position: relative;
color: #FFF;
}
Here is the Demo
This is certainly not complete, but it should give you a good start. The main thing I would suggest is focusing on your ul li groupings: JS Fiddle
HTML
<div id="menu">
<ul>
<li class="current_page_item">Home
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>Hardware
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>About Us
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>sjabloon
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
<li>Contact Us
<ul>
<li>Hardware2
</li>
<li>Hardware3
</li>
</ul>
</li>
</ul>
</div>
CSS
#menu {
position: absolute;
right: 0;
}
#menu ul {
display: inline-block;
line-height: 1em;
position: relative;
/* naast elkaar*/
right: 0;
list-style: none;
/*display: inline-table;*/
}
/*
#menu ul: after
{
content: "";
clear: both;
display: inline-block;
}*/
#Menu ul li ul {
height: 0;
}
#Menu ul li:hover > ul {
height: 10px;
}
#menu ul li {
/* op een lijn */
padding: 1em;
letter-spacing: 0.20em;
font-size: 0.90em;
text-transform: uppercase;
color: #OOC;
outline: 0;
}
#menu ul li:hover {
background: #00F;
}
#menu ul li:hover a {
color: #FFF;
}
#menu ul li a
/*#menu ul li span*/
{
letter-spacing: 0.20em;
text-decoration: none;
/* geen onderlijning*/
font-size: 0.90em;
font-weight: 600;
text-transform: uppercase;
outline: 0;
color: #OOC;
}
#menu ul li ul
/* submenu*/
{
width: 86px;
background: #00F;
height: 0;
overflow: hidden;
text-align: center;
display: block;
-webkit-transition: all .8s ease;
-moz-transition: all .8s ease;
-ms-transition: all .8s ease;
-o-transition: all .8s ease;
transition: all .8s ease;
position: absolute;
}
#menu ul:hover > li ul {
height: 90px;
width: 86px;
padding: 20px;
}
#menu ul li ul li {
/*onder mekaar */
border-top: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
color: #FFF;
}
Related
I need to display sub-sub-menu on hover of my sub-menu. So far I did code to display menu -> sub-menu on menu click, but to proceed I want a functionality to display sub-sub-menu on hover of my sub-menu. Can somebody help me to achieve the same?
var ddmenuitem = 0;
function jsddm_open() {
jsddm_close();
ddmenuitem = $(this).find('ul.submenu').css('display', 'block');
// $(this).find('div.subsubmenu').css('display','none');
}
function jsddm_close() {
if (ddmenuitem) ddmenuitem.css('display', 'none');
}
$(document).ready(function() {
$('#topnav > ul > li').bind('click', jsddm_open)
$('#topnav > ul > li > a').click(function(ev) {
if ($(this).hasClass('current')) {
ev.preventDefault();
}
if ($(this).attr('class') != 'active') {
$('#topnav ul li a').removeClass('active');
$(this).addClass('active');
}
});
});
#topnav {
float: left;
width: 600px;
height: 30px;
background: black;
margin-top: 10px;
position: relative;
font-size: 15px;
margin-left: 30px
}
#topnav ul {
list-style: none;
padding: 0px;
margin: 0px;
}
#topnav ul li {
float: left;
margin: 0;
padding: 0;
}
#topnav ul li a {
padding: 5px 15px;
color: red;
text-decoration: none;
display: block;
font-weight: bold;
}
#topnav ul li a:link {
color: red;
text-decoration: none;
}
#topnav ul li a:visited {
color: #FFF;
text-decoration: none;
}
#topnav ul li a:hover {
color: red;
text-decoration: none;
}
#topnav ul li a.active {
text-decoration: none;
color: black;
background: #e0e0e0;
}
#topnav ul li ul.submenu {
float: left;
padding: 4px 0;
position: absolute;
left: 0;
top: 30px;
display: none;
background: #e0e0e0;
color: #00537F;
width: 600px;
height: 30px;
}
#topnav ul li ul.submenu a {
display: inline;
color: #00537F;
padding: 4px 8px;
}
#topnav ul.submenu a:hover {
background-color: black;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="topnav">
<ul>sds
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
Try the following snippet without using jquery or javascript, you can get it done using only css. And have updated according to your question
#nav {
list-style: none inside;
margin: 0;
padding: 0;
text-align: center;
}
#nav li {
display: block;
position: relative;
float: left;
background: #000000;
}
#nav li a {
display: block;
padding: 0;
text-decoration: none;
width: 200px;
line-height: 35px;
color: #fff;
}
#nav li li a {
font-size: 80%;
}
#nav li:hover {
background: #ff0000;
}
#nav ul {
position: absolute;
padding: 0;
left: 0;
display: none;
}
#nav li:hover ul ul {
display: none;
}
#nav li:hover ul {
display: block;
}
#nav li li:hover ul {
display: block;
margin-left: 200px;
margin-top: -35px;
}
<div id="topnav">
<ul id="nav">
<li>
Admin
</li>
<li>
MAC
<ul class="submenu">
<li>Master Data</li>
<li>
Transaction Data ⇒
<ul>
<li>Company Master</li>
<li>Location Master</li>
<li>Size Master</li>
</ul>
</li>
<li>
Admin Data
</li>
</ul>
</li>
</ul>
</div>
you can try 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>Sub Menu</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</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>
On my home page the dropdown ul looks exactly how I want it to:
But on all my other pages the ul looks much bigger like this:
Here is the HTML for the home page:
<header id="header" class="alt">
<h1><strong>South Somerset Motocross Club</strong></h1>
<nav id="nav">
<ul>
<li>Home</li>
<li><a>Info</a>
<ul class="alt">
<li>Club Rules</li>
<li>Pre-Race Bike Check</li>
<li>Job Descriptions</li>
<li>Race Fees</li>
<li>Groups And Ages</li>
</ul>
</li>
<li><a>About Us</a>
<ul class="alt">
<li>Our Heritage</li>
<li>Committee</li>
</ul>
</li>
<li>News</li>
<li>Fixtures</li>
</ul>
</nav>
</header>
Here is the HTML for the other page:
<header id="header">
<h1><strong>South Somerset Motocross Club</strong></h1>
<nav id="nav">
<ul>
<li>Home</li>
<li><a>Info</a>
<ul class="alt">
<li>Club Rules</li>
<li>Pre-Race Bike Check</li>
<li>Job Descriptions</li>
<li>Race Fees</li>
<li>Groups And Ages</li>
</ul>
</li>
<li><a>About Us</a>
<ul class="alt">
<li>Our Heritage</li>
<li>Committee</li>
</ul>
</li>
<li><a>News</a></li>
<li>Fixtures</li>
</ul>
</nav>
</header>
Here is the CSS for both:
#header {
background-color: #fff;
border-bottom: solid 1px rgba(144, 144, 144, 0.25);
box-shadow: 0px 0.0375em 0.125em 0px rgba(0, 0, 0, 0.05);
color: #000;
cursor: default;
font-size: 1.25em;
height: 4.5em;
left: 0;
line-height: 4.4em;
position: fixed;
text-transform: uppercase;
top: 0;
width: 100%;
z-index: 10000;
z-index: 10001;
}
#header a {
color: #000;
}
#header h1 {
color: #000;
font-weight: 400;
height: inherit;
left: 1.25em;
line-height: inherit;
margin: 0;
padding-left: 10px;
padding-right: 10px;
position: absolute;
top: 0;
}
#header nav {
height: inherit;
line-height: inherit;
position: absolute;
right: 1.25em;
top: 0;
vertical-align: middle;
}
#header nav ul {
list-style: none;
margin: 0;
padding-left: 0;
}
#header nav ul li {
color: #fff;
display: inline-block;
padding-top: 0;
padding-bottom: 0;
padding-left: 10px;
padding-right: 10px;
margin-left: 1em;
}
#header nav ul li ul {
display: none;
padding: 0;
margin: 0;
background-color: #eee;
border-radius: 4px;
}
#header nav ul li:hover ul {
display: block;
position: absolute;
}
#header nav ul li ul li {
border-radius: 4px;
margin: 0 0 0 0;
padding-left: 4px;
padding-top: 0;
padding-right: 50px;
display: block;
color: black;
font-size: 12pt;
}
#header nav ul li ul li a {
color: #111;
padding: 0;
margin: 0;
display: block;
}
#header nav ul li ul li a:hover {
color: rgba(255, 255, 0, 1);
}
#header.alt nav ul li ul li a:hover {
color: rgba(255, 255, 0, 1);
}
#header.alt nav ul li ul li:hover {
background-color: #3477ff;
}
#header nav ul li ul li:hover {
background-color: #3477ff;
}
#header.alt nav ul li ul li a {
color: #000;
padding: 0;
display: block;
}
#header nav ul li a {
-moz-transition: color 0.1s ease-in-out;
-webkit-transition: color 0.1s ease-in-out;
-ms-transition: color 0.1s ease-in-out;
transition: color 0.1s ease-in-out;
color: #000;
display: inline-block;
text-decoration: none;
}
#header nav ul li a:hover {
color: #000;
}
#header nav ul li .button {
border-color: rgba(144, 144, 144, 0.25);
box-shadow: none;
height: 3em;
line-height: 2.9em;
margin-bottom: 0;
padding: 0 1.5em;
position: relative;
top: -0.075em;
vertical-align: middle;
}
#header .container {
position: relative;
}
#header .container h1 {
left: 0;
}
#header .container nav {
right: 0;
}
#header.alt {
background-color: transparent;
border: 0;
box-shadow: none;
height: 3.25em;
line-height: 3.25em;
position: absolute;
}
#header.alt h1 {
color: #ffffff;
left: 2.5em;
top: 2em;
}
#header.alt h1 a {
color: #FFF;
}
#header.alt nav {
right: 2em;
top: 2em;
}
#header.alt nav a {
color: #ddd;
}
#header.alt nav a:active, #header.alt nav a:hover {
color: #FFF;
}
#header.alt .button {
border-color: rgba(255, 255, 255, 0.5);
color: #ffffff !important;
}
#media screen and (max-width: 980px) {
#header {
display: none;
}
}
I would like the other page's <ul> elements to be the same size as the home page but I can't seem to find any extra margins or padding on them.
It is because of the alt class. The ul li ul li gets a line-height from the alt class.
So force the same line-height upon the #header nav ul li ul li by adding the same line-height. Which is line-height: 3.25em;.
The issue is down to your line heights - they are set on #header and #header.alt to different values:
#header.alt:
line-height: 3.25em;
#header:
line-height:4.4em;
This is causing the difference you are seeing in your nav links.
I want to build a menu that is CSS only. No jQuery.
I've gotten this far but can't make the menu slide in from the top. Here's a fiddle (oddly enough, it doesn't look like my menu... but all the styles are there)
Some code: The HTML:
<div class="menu">
<ul>
<li class="blue"> <a style="text-decoration: none" href="/who-we-are">Who We Are</a>
</li>
<li class="red"> <a style="text-decoration: none" href="/services">Services</a>
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="orange"><a style="text-decoration: none" href="/packages">Packages</a>
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="green"><a style="text-decoration: none" href="/contact-us">Contact</a>
</li>
</ul>
</div>
And my CSS:
.menu {
float: left;
margin-top: 0px;
}
.blue, div.item.blue div {
color: #009dc4;
}
.red, div.item.red div {
color: #fe4f00;
}
.orange, div.item.orange div {
color: #ff5958;
}
.green, div.item.green div {
color: #50c402;
}
.menu ul li a {
display: block;
height: 45px;
padding-top: 18px;
}
.menu ul li a:visited {
color: inherit;
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
display: inline-block;
position: relative;
cursor: pointer;
width: 145px;
font-family: Georgia;
height: 45px;
font-size: 20px;
line-height: 22px;
font-weight: bold;
padding-left: 5px;
margin-top: 0px;
margin-right: 46px;
border-bottom: 5px solid;
z-index: 5000;
}
.menu ul li:hover {
color: #ffffff !important;
}
.menu ul li.blue:hover {
background-color: #009dc4;
border-bottom: 5px solid #009dc4;
}
.menu ul li.red:hover {
background-color: #fe4f00;
border-bottom: 5px solid #fe4f00;
}
.menu ul li.orange:hover {
background-color: #ff5958;
border-bottom: 5px solid #ff5958;
}
.menu ul li.green:hover {
background-color: #50c402;
border-bottom: 5px solid #50c402;
}
.menu ul li ul {
display: none;
opacity: 0;
visibility: hidden;
position: absolute;
top: 45px;
}
.menu ul li ul li {
display: block;
font-size: 12px;
border-bottom: none;
width: 145px;
color: #ffffff;
padding-left: 0px;
height: 34px;
line-height: normal;
position: relative;
left: -5px;
}
.menu ul li ul li a {
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
height: auto;
padding: 10px 5px;
font-size: 12px;
background-color: #4fc7c1;
-webkit-transition: all 0.1s;
-moz-transition: all 0.1s;
-ms-transition: all 0.1s;
-o-transition: all 0.1s;
transition: all 0.1s;
}
.menu ul li ul li a:hover {
background: #a3edf5;
}
.menu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
.menu > ul > li:last-of-type {
margin-right: 0px;
}
If someone can just help with getting the slide down to work, I'd appreciate it.
Unfortunately there is no way to animate height:0 to height:auto with CSS (as of CSS3). However there is a workaround using max-height documented here: http://css3.bradshawenterprises.com/animating_height/
With that logic I have created a simple example from your JS fiddle. All it does is set the css style max-height:0 on the drop-down <ul> element, some transitions for the max-height css attribute and then a large max-height value on menu hover.
Unfortunately the max-height must be hard-coded (cannot be auto) so we are limited here; but if you are confident that your menus will never exceed say 500px then you would simply put 500px.
Here's the fiddle:
http://jsfiddle.net/6ame5wcu/4/
All you need to do is to set max-height:0; and overflow:hidden; then add a transition on it like this:
.menu ul li ul {
max-height:0em;
overflow:hidden;
position: absolute;
top: 45px;
transition:max-height .9s ease
}
on :hover set a max-height ie max-height:600px;
.menu ul li:hover ul {
max-height:600px;
}
DEMO
Full code:
<div class="menu">
<ul>
<li class="blue"> Who We Are
</li>
<li class="red"> Services
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="orange">Packages
<ul>
<li> Post 1
</li>
<li> Post 2
</li>
<li> Post 3
</li>
</ul>
</li>
<li class="green">Contact
</li>
</ul>
</div>
css
a{text-decoration: none}
.menu {
float: left;
margin-top: 0px;
}
.blue, div.item.blue div {
color: #009dc4;
}
.red, div.item.red div {
color: #fe4f00;
}
.orange, div.item.orange div {
color: #ff5958;
}
.green, div.item.green div {
color: #50c402;
}
.menu ul li a {
display: block;
height: 45px;
padding-top: 18px;
}
.menu ul li a:visited {
color: inherit;
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
display: inline-block;
position: relative;
cursor: pointer;
width: 145px;
font-family: Georgia;
height: 45px;
font-size: 20px;
line-height: 22px;
font-weight: bold;
padding-left: 5px;
margin-top: 0px;
margin-right: 46px;
border-bottom: 5px solid;
z-index: 5000;
}
.menu ul li:hover {
color: #ffffff !important;
}
.menu ul li.blue:hover {
background-color: #009dc4;
border-bottom: 5px solid #009dc4;
}
.menu ul li.red:hover {
background-color: #fe4f00;
border-bottom: 5px solid #fe4f00;
}
.menu ul li.orange:hover {
background-color: #ff5958;
border-bottom: 5px solid #ff5958;
}
.menu ul li.green:hover {
background-color: #50c402;
border-bottom: 5px solid #50c402;
}
.menu ul li ul {
max-height:0em;
overflow:hidden;
position: absolute;
top: 45px;
transition:max-height .9s ease
}
.menu ul li:hover ul {
max-height:600px;
}
.menu ul li ul li {
display: block;
font-size: 12px;
border-bottom: none;
width: 145px;
color: #ffffff;
padding-left: 0px;
height: 34px;
line-height: normal;
position: relative;
left: -5px;
}
.menu ul li ul li a {
font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
height: auto;
padding: 10px 5px;
font-size: 12px;
background-color: #4fc7c1;
-webkit-transition: all 0.1s;
-moz-transition: all 0.1s;
-ms-transition: all 0.1s;
-o-transition: all 0.1s;
transition: all 0.1s;
}
.menu ul li ul li a:hover {
background: #a3edf5;
}
.menu > ul > li:last-of-type {
margin-right: 0px;
}
I have HTML Menu and Submenu. For some reason, the submenu hides when I' am hovering over them. When I hover on the parent menu, submenu shows and as soon as am hovering over the submenu it hides.
HTML
<div id="main-menu">
<ul>
<li>Home<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">Start here</span></li>
<li>Features<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">remix all features</span>
<ul class="transparency">
<li>Accordion</li>
<li>Buttons</li>
<li>Typography</li>
</ul>
</li>
<li>MP3<span class="sub">full archive</span></li>
<li>Video<span class="sub">latest clips</span></li>
<li>Gallery<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">Photo Gallery</span>
<ul class="transparency">
<li>Gallery 4 Column</li>
<li>Gallery 3 Column</li>
<li>Gallery 2 Column</li>
</ul>
</li>
<li>Pages<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">more templates</span>
<ul class="transparency">
<li>RTL Support</li>
<li>Events</li>
<li>MP3 Single Wide</li>
</ul>
</li>
<li>Blog<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">latest news</span>
<ul class="transparency">
<li>Blog</li>
<li>Blog Left Sidebar</li>
<li>Blog Both Sidebar</li>
</ul>
</li>
</ul>
</div>
CSS
#main-menu{
float: right;
position: relative;
margin: 20px 0 0 -20px;
}
#main-menu ul{
float: right;
padding: 0;
position: relative;
margin: 0;
list-style: none;
}
#main-menu li{
float: left;
position: relative;
padding: 0;
}
#main-menu a{
padding:0 20px 22px 0;
display: block;
position: relative;
color: #fff;
text-transform: uppercase;
font-size: 14px;
text-decoration: none;
font-weight: bold;
}
#main-menu li a span {
font-size: 12px;
font-family: tahoma;
font-weight: normal;
text-transform: none;
display: block;
color: #AFAFAF;
margin: 10px 0 0 0;
}
#main-menu li ul{
display: none;
position: absolute;
width: 170px;
word-break: break-all;
}
#main-menu li:hover > ul{
display: block;
margin-top: 11px;
}
#main-menu li > ul li{
display: block;
width: 100%;
}
#main-menu li > ul li a:hover{
display: block;
width: 100%;
background: #FFF;
color: #000;
}
#main-menu li > ul li a{
font-weight: normal;
padding: 8px 15px;
line-height: 20px;
color: #fff;
text-transform: none;
letter-spacing: 0;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
Live demo
Just replace the margin-top by padding-top in this CSS:
#main-menu li:hover > ul {
display: block;
margin-top: 11px;
}
So that it becomes:
#main-menu li:hover > ul {
display: block;
padding-top: 11px;
}
Proof:
you can update the
#main-menu li ul{
display: none;
position: absolute;
left:0;
top:0;
width: 170px;
word-break: break-all;
}
and
#main-menu li > ul li a{
font-weight: normal;
padding: 8px 15px;
line-height: 20px;
color: #000;
text-transform: none;
letter-spacing: 0;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
further alignments u cand update as u want
Change margin-top to padding-top, like so:
#main-menu li:hover > ul {
display: block;
padding-top: 11px;
}
I make pure css menu with 2 levels .But now I need to make it 3 levels .I tried many time but not working for me . here is the jsfiddle .
I don't need any jquery code, just pure css .
CSS
#menu {
width: 980px;
height: 30px;
float: left;
border-top: dashed 1px #d8d8d8;
margin-left: 7px;
}
#menu ul.Mainmenu {
width: 996px;
margin: 0px;
padding: 0px;
margin-top: 10px;
}
#menu ul.Mainmenu li {
float: left;
list-style: none;
margin-right: 20px;
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
color: #860300;
margin-right: 16px\9; /* IE8 and below */
position: relative;
height: 30px;
}
#menu ul.Mainmenu li a {
text-decoration: none;
font-family: Verdana, Geneva, sans-serif;
font-size: 13px;
color: #860300;
}
ul li ul {
padding: 0;
position: absolute;
top: 25px;
left: -10px;
width: 190px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.5s;
-moz-transition: opacity 0.5s;
-ms-transition: opacity 0.5s;
-o-transition: opacity 0.5s;
-transition: opacity 0.5s;
z-index: 100000;
width: 200px;
background-color: #FFF;
padding: 7px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
ul li ul li {
color: #fff;
float: left;
width: 190px;
height: auto !important;
min-height: 20px;
margin-bottom: 9px;
line-height: 18px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
padding-top: 3px;
padding-left: 3px;
}
ul li ul li a {
color: #fff;
font-size: 12px !important;
}
ul li ul li:hover {
background: #820B06;
color: #FFF;
}
ul li ul li:hover a {
color: #FFF !important;
}
ul li:hover ul {
opacity: 1;
visibility: visible;
}
Thanks guys
See this example
css
#nav ul{
margin:0;
padding:0;
list-style:none;
}
#nav ul li{
margin:0;
padding:10px 20px;
position:relative;
height:20px;
line-height:20px;
background-color:#EEE;
}
#nav > ul > li {
float: left;
height:30px;
line-height:30px;
background-color:#CCC;
}
#nav li > ul{
visibility:hidden;
width:200px;
position: absolute;
top:0px;
left:200px;
border-left:1px solid #000;
}
#nav > ul > li > ul{
top:50px;
left:0;
}
#nav li:hover{
background-color:#999;
}
#nav li:hover > ul{
visibility:visible;
}
html
<div id="nav">
<ul>
<li>Level 1
<ul>
<li>Level 2-1</li>
<li>Level 2-2
<ul>
<li>Level 3-1</li>
<li>Level 3-2</li>
</ul>
</li>
</ul>
</li>
</ul>
Here i added sample CSS Menu with level 3. Please check and let me know. Hope it should helpful for you. Thanks.
.third-level-menu
{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.third-level-menu > li
{
height: 30px;
background: #999999;
}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
.second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}
/* Menu Link Styles */
.top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
<ul class="top-level-menu">
<li>About</li>
<li>Services</li>
<li>
Offices
<ul class="second-level-menu">
<li>Chicago</li>
<li>Los Angeles</li>
<li>
New York
<ul class="third-level-menu">
<li>Information</li>
<li>Book a Meeting</li>
<li>Testimonials</li>
<li>Jobs</li>
</ul>
</li>
<li>Seattle</li>
</ul>
</li>
<li>Contact</li>
</ul>
I have also put together a live demo here http://jsfiddle.net/4ScFz/400/ that's available to play with.