I have a Pure CSS3 Navigation Menu where child level appears behind parent level.
Tried to resolve it by playing with z-index and other elements for 5 days now.
Thanks in advance!
Here's the HTML(direction RTL):
<div id="MainNavMenu">
<div id="main_navigation" class="blue main-menu "><!-- START -->
<ul>
<li class="main_list_item"><a class="main_list_link" href="#">Marketing</a>
<ul>
<li>NPA
<li>PMN
<li>NML
<ul>
<li>Document Library</li> <!-- Third Level -->
</ul>
</li>
<li>Cataloges</li>
<li>Price lists</li>
</ul>
</li>
<li class="main_list_item"><a class="main_list_link" href="#">פיתוח</a>
<ul>
<li>Document Library</li>
<li>Project Management</li>
<li>QA</li>
<li>Administration</li>
<li>R&D Mechanics</li>
<li>Catalog</li>
<li>Mtb</li>
<li>Itbs</li>
<li>Eit</li>
</ul>
</li>
<li class="main_list_item"><a class="main_list_link" href="#">משהו</a>
<ul>
<li>מכונות
<ul>
<li>ליב</li>
<li>MSG</li>
<li>Type</li>
<li>DIff</li>
</ul>
</li>
<li>בטיחות
<ul>
<li>נהלי בג"ס</li>
<li>מפרטים</li>
<li>טפסים</li>
<li>איכות הסביבה</li>
<li>בטיחות וגיהות</li>
<li>בריאות וארגונומיה</li>
<li>מידע ותקנים</li>
<li>MSDS</li>
</ul>
</li>
<li>משק ובטחון
<ul>
<li>ספריות מסמכים</li>
</ul>
</li>
<li>אבטחת איכות
<ul>
<li>מדריכי משתמש</li>
<li>מפרטים מחלקתיים</li>
<li>דו"חות מנטי</li>
<li>תעודות איכות</li>
</ul>
</li>
<li>רכש
<ul>
<li>ספריות מסמכים</li>
<li>חוזי ספק</li>
<li>TTR פלדות</li>
<li>FDT השחזה</li>
</ul>
</li>
</ul>
</li>
<li class="main_list_item"><a class="main_list_link" href="#">חברה שלי</a>
<ul>
<li>ספר טלפונים</li> <!-- SECOND LEVEL MENU -->
<li>טלפונים חשובים</li>
<li>פתיחת תקלת מחשוב</li>
<li>פינת נוסטלגיה</li>
<li>ימי הולדת</li>
<li>שערי מטבע</li>
<li>המתבח של ישקר</li>
<li>אירועים</li>
<li>ספריות מסמכים</li>
<li>משאבי אנוש
<ul>
<li>טפסים</li>
<li>מסמכי ביטוח</li>
<li>מידע והטבות</li>
<li>נהלים</li>
<li>הודעות</li>
<li>אירועים</li>
</ul>
</li>
</ul>
</li>
</ul>
</div> <!-- MAIN NAVIGATION END -->
</div>
Here is CSS:
/**************************************
Navigation Menu
***************************************/
#MainNavMenu
{
left: 1040px;
top: 70px;
position: absolute;
width: -moz-fit-content;
width: -webkit-fit-content;
width: fit-content;
margin: auto;
height: 18px;
z-index:3;
}
#main_navigation{
width: -moz-fit-content;
width: -webkit-fit-content;
width: fit-content;
margin: auto;
font-size:8px;height:20px;float:right;
outline:none;
margin-bottom:250px;
box-shadow:1px 0px 2px rgba(0,0,0,0.5);
opacity: 1;
border-radius:5px;
}
.main-menu{position:relative;z-index:7;font-family: 'Ariel', tahoma, serif;letter-spacing:0pt; solid;}
.main-menu ul li a, .main-menu ul li a:link, .main-menu ul li a:visited{border-bottom:4pt solid transparent;padding-bottom:1px}
.main-menu ul {
margin:0;
padding:0px;
list-style-type:none;
z-index:5;
border-radius:5px;
}
.main-menu ul li {
position:relative;
display:inline;
float:right;
z-index:4;
}
/*Second level settings*/
.main-menu ul li > ul {
z-index:2;
visibility:hidden;
display:inline;
opacity:0;
padding:0px;margin:0px;
position:absolute;
/*width: -moz-fit-content;
width: -webkit-fit-content;
width: fit-content;*/
width: 150px;
top:25px;
right:40px;
color:#FFFFFF;
-webkit-transition:all 0.3s ease-in-out;
-moz-transition:width 0.3s ease-in-out;
-o-transition:all 0.3s ease-in-out;
transition:all 0.3s ease-in-out;
}
/*on hover over second level - third level appears*/
.main-menu ul li ul li:hover > ul {
display:block;
visibility:visible;
right:50px;
top: 15px;
opacity: 1;
z-index: 9999;
}
.main-menu ul li:hover > ul {
display:block;
visibility:visible;
right:0px;
display:block;
opacity:1;
}
.main_list_item {
height:20px;
z-index:0;
}
.main-menu ul li a.main_list_link,.main-menu ul li a.main_list_link:link{
line-height:20px;
text-shadow:none;
font-size:12px;
text-transform:uppercase;
}
.main-menu ul li > a {
display:block;
text-decoration:none;
overflow:hidden;
padding:0px 15px;
border-radius:3px;
}
* html .main-menu ul li a {
display:inline-block;
}
.main-menu ul li ul li {
display:list-item;
float:right;
border-left:none!important;
color:#FFFFFF;
padding:0px;margin:0px;
}
.main-menu ul li ul li a {
margin:0px;
-webkit-transition:all 0.3s ease-in-out;
-moz-transition:width 0.3s ease-in-out;
-o-transition:all 0.3s ease-in-out;
transition:all 0.3s ease-in-out;
}
.main-menu ul li ul li{
-webkit-transition:all 0.3s ease-in-out;
-moz-transition:all 0.3s ease-in-out;
-o-transition:all 0.3s ease-in-out;
transition:all 0.3s ease-in-out;
border-bottom:solid 1px #ececec;
width:100%;
}
.main-menu ul ul {
background:#FFFFFF;
border:1px solid #e0e0e0;
-moz-box-shadow:0px 3px 3px rgba(0,0,0,0.1);
-webkit-box-shadow:0px 3px 3px rgba(0,0,0,0.1);
box-shadow:0px 3px 3px rgba(0,0,0,0.1);
z-index:9;
color:#707070;
}
.main-menu ul ul li a,.main-menu ul ul li a:visited,.main-menu ul ul li a:link {
height:100%;
text-transform: capitalize;
margin-right:0px!important;
margin-left:0px!important;
font-size:12px;
color:#707070;
z-index:10;
background-color: #FFFFFF ;
}
/*TEMP*/
/*TEMP*/
.main-menu ul ul li:hover > a{
cursor:pointer;
text-decoration:none!important;
padding-right:30px;
right: 40px;
z-index:11;
}
.main-menu ul ul li > a:after{
content:"";
opacity:0;
position:absolute;
right:20px;top:26px;
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-right:5px solid #FEFEFE;
-webkit-transition:all 0.2s ease-in-out;
-moz-transition:all 0.2s ease-in-out;
-o-transition:all 0.2s ease-in-out;
transition:all 0.2s ease-in-out;
z-index:12;
}
/*arrow pointer inside menu item*/
.main-menu ul ul li:hover > a:after{
content:"";
opacity:1;
position:absolute;
right:0px;top:5px;
width: 0;
height: 0;
border-right:5px solid #FEFEFE;
}
.main-menu ul ul ul {
position:absolute;
right: 100px;
top :20px;
}
/***********
Menu Color
************/
/* BLUE */
.blue{
background:#148cfc;
/*border:2px solid #ffd017;*/ /*yellow border*/
}
.blue ul ul{
border-top:2px solid #ffd017;
width:99%;
}
.blue ul ul li:hover > a{
text-decoration:none!important;
color:#FFF!important;
background:#148cfc;
padding-right:30px;
text-shadow:1px 0px 0px #3080b0;
}
.blue ul li a{
color:#FFFFFF;
}
.blue ul li > a:hover,.blue ul li:hover > a{
color:#ffd017!important;
}
/*menu items separator*/
.blue .main_list_item:after{
content:"";
z-index:-1;
position:absolute;
border-right:1px solid #e9e9e9;
box-shadow:1px 0px 0px #057794;
height:15px;
top:3px;
background:#FFF;
}
/*FIXING border */
.main_list_item:first-child:after{
border-right:none;
}
/**************************************
End Of Navigation Menu
***************************************/
Related
In Chrome the ul li ul border is exact over de border of the menu ul, but in Internet Explorer and Firefox it's off by 1px.
http://jsfiddle.net/5qasu929/
#menu ul li ul {
display:none;
position:absolute;
z-index:999;
height:auto;
margin-top:16px;
margin-left:-0px;
background-color:#EFEFEF;
border-bottom:1px solid #C7C7C7;
border-left:1px solid #C7C7C7;
border-right:1px solid #C7C7C7;
}
#menu ul li {
display:table-cell;
height:50px;
vertical-align:middle;
border-bottom:1px solid #C7C7C7;
margin-left:0;
}
How can I fix this?
A couple of changes should make this more uniform across browsers:
Add position:relative; to #menu ul li to make the child ul position relative to it
Add top:50px; to #menu ul li ul. This is the same as the height of the parent li
Remove margin-top:16px; from #menu ul li ul
#menu {
width: 950px;
margin: 0px auto;
list-style: none;
position: relative;
}
#menu ul {
list-style: none;
float: left;
}
#menu ul li {
display: table-cell;
height: 50px;
vertical-align: middle;
border-bottom: 1px solid #C7C7C7;
margin-left: 0;
position: relative; /*Add*/
}
#menu ul li a {
font-size: 18px;
color: #024fff;
text-decoration: none;
font-family: 'Raleway', sans-serif;
padding: 5px;
}
#menu ul li:hover {
background-color: #E3E3E3;
border-bottom: 1px solid #024fff;
-webkit-transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
}
#menu ul li ul {
display: none;
position: absolute;
z-index: 999;
height: auto;
/*margin-top:16px;Remove*/
margin-left: -0px;
background-color: #EFEFEF;
border-bottom: 1px solid #C7C7C7;
border-left: 1px solid #C7C7C7;
border-right: 1px solid #C7C7C7;
top: 50px;/*Add*/
}
#menu ul li:hover > ul {
display: block;
border-top: 1px solid #024fff;
}
#menu ul li ul li {
min-width: 80px;
display: block;
height: 23px;
padding: 9px 35px 0px 5px;
border: 0px;
}
#menu ul li ul li:hover {
border-bottom: 0px;
}
#menu ul li ul li:before {
content: '- \00a0 ';
color: #024fff;
}
#menu ul li ul li a {
font-size: 16px;
padding: 3px;
}
<div id="menu">
<ul>
<li>Home
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
<li>Home2
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
<li>Home3
</li>
<li>Home4
<ul>
<li>Sub1
</li>
<li>Sub1
</li>
<li>Sub1
</li>
</ul>
</li>
</ul>
</div>
Use border-box property of css,
Specify that <li> elements should have padding and border included in
the element's total width and height:
#menu ul li {
box-sizing:border-box;
margin-top:-1px;
}
You should use the A tag height within a parent LI in order to position your sub menu
First, add a display:block and height:100% to your A:
#menu ul li a {
font-size:18px;
color:#024fff;
text-decoration:none;
font-family: 'Raleway', sans-serif;
padding:5px;
display:block;
height:100%;
}
Delete Li's height (Height will depend on the font-size & padding of your A tag
#menu ul li {
display:table-cell;
height:auto;
vertical-align:middle;
border-bottom:1px solid #C7C7C7;
margin-left:0;
}
And finally remove margin-top toi submenu :
#menu ul li ul {
display:none;
position:absolute;
z-index:999;
height:auto;
/*margin-top:16px;*/
margin-left:-0px;
background-color:#EFEFEF;
border-bottom:1px solid #C7C7C7;
border-left:1px solid #C7C7C7;
border-right:1px solid #C7C7C7;
}
Prevent submenu > a from being display:block:
#menu ul li ul li a {
font-size:16px;
padding:3px;
display:inline;
}
Live example
I have a list for my navbar. I want to have a border below the active li item, not just on the bottom.
I've been able to add the border to the bottom using border-bottom, but again, it needs to be below the li element. Any help would be appreciated.
Here is my custom css so far, in addition to default Bootstrap navbar list:
.nav .active{
border-bottom: 5px solid yellow;
}
See below:
Just an example ..... use border-bottom with background-clip padding box
ul {
list-style-type: none;
}
li {
height: 50px;
width: 180px;
line-height: 50px;
border-bottom: 5px solid transparent;
background: #ddd;
display: inline-block;
text-align: center;
background-clip: padding-box;
}
li:hover {
border-bottom: 5px solid gold;
}
<ul>
<li>Hello</li>
<li>World</li>
</ul>
Altarnatively you can try box shadow. see this
ul {
list-style-type: none;
}
li {
height: 50px;
width: 180px;
line-height: 50px;
background: #ddd;
display: inline-block;
text-align: center;
}
li:hover {
box-shadow: 0 5px 0 0 gold;
}
<ul>
<li>Hello</li>
<li>World</li>
</ul>
Try like this: demo
CSS:
ul.nav {
list-style-type: none;
}
li {
display:block;
float:left;
line-height: 26px;
margin-right:10px;
background-color:#ccc;
padding:4px 10px;
border-bottom: 5px solid transparent;
}
li a{
text-decoration:none;
color:#000;
}
li:hover, li.active {
border-bottom: 5px solid red;
}
HTML:
<ul class="nav">
<li> Menu 1
</li>
<li class="active"> Menu 1
</li>
<li> Menu 1
</li>
<li> Menu 1
</li>
</ul>
I typically use an :after for small details like this, to get the border outside the menu items normal height.
HTML:
<ul>
<li>Home</li>
<li class="active">About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
<div class="main">
Next Box
</div>
CSS:
html,body{
margin:0px;
padding:0px;
}
ul{
/* for looks */
list-style:none;
margin:0px;
padding:0px;
}
li{
background:black;
color:white;
display:inline-block;
margin:0px;
padding:5px 20px;
}
li.active{
position:relative;
}
li.active:after{
content:'';
position:absolute;
top:100%;
left:0px;
border-top:5px solid yellow;
width:100%;
}
.main{
background-color:#dddddd;
min-height:400px;
}
Most of the css is just for presentation but the key stuff is on the li, the li.active, and the li.active:after.
You can check out my demo at jsfiddle
This is the sample I always use. Hope this can help you ;)
This method is using the last child of the "li" element as the border.
The class "selected" on "li" element choose the position of the border to stay at initial.
When the mouse is on one of the menu bar button, the bar will follow it by an animation.
If you don't want an animation, please just delete ALL transition CSS style in ".menu > li:last-child" class.
If you want to know more about last child CSS style, please go to this link >> http://www.w3schools.com/cssref/sel_last-child.asp
.menu, .menu li {
margin: 0;
padding: 0;
list-style: none;
display: inline-block;
}
.menu {
margin: auto;
position: relative;
overflow: hidden;
height: 25px;
}
.menu li {padding: 0px 5px;}
.menu > li {
text-align: center;
width: 80px;
font-size: 14px;
}
.menu > li > a {
display: block;
padding: 0px 0px;
color: #444;
text-decoration: none;
font-size: 15px;
-webkit-transition: color 0.5s ease;
-moz-transition: color 0.5s ease;
-ms-transition: color 0.5s ease;
-o-transition: color 0.5s ease;
transition: color 0.5s ease;
}
.menu li a:hover {
color: #ffa500;
}
.menu > li:last-child {
position: absolute;
top: 20px;
right: -90px;
height: 5px;
width: 80px;
background: #ffa500;
-webkit-transition: transform 0.5s ease;
-moz-transition: transform 0.5s ease;
-ms-transition: transform 0.5s ease;
-o-transition: transform 0.5s ease;
transition: transform 0.5s ease;
}
.menu .selected {
position: relative;
pointer-events: none;
cursor: default;
}
.selected a {
color: #ffa500 !important;
}
.menu li:nth-child(1):hover ~ li:last-child {
-webkit-transform:translateX(-375px) !important;
-moz-transform:translateX(-375px) !important;
-ms-transform:translateX(-375px) !important;
-o-transform:translateX(-375px) !important;
transform:translateX(-375px) !important;
}
.menu li:nth-child(1).selected ~ li:last-child {
-webkit-transform:translateX(-375px);
-moz-transform:translateX(-375px);
-ms-transform:translateX(-375px);
-o-transform:translateX(-375px);
transform:translateX(-375px);
}
.menu li:nth-child(2):hover ~ li:last-child {
-webkit-transform:translateX(-280px) !important;
-moz-transform:translateX(-280px) !important;
-ms-transform:translateX(-280px) !important;
-o-transform:translateX(-280px) !important;
transform:translateX(-280px) !important;
}
.menu li:nth-child(2).selected ~ li:last-child {
-webkit-transform:translateX(-280px);
-moz-transform:translateX(-280px);
-ms-transform:translateX(-280px);
-o-transform:translateX(-280px);
transform:translateX(-280px);
}
.menu li:nth-child(3):hover ~ li:last-child {
-webkit-transform:translateX(-185px) !important;
-moz-transform:translateX(-185px) !important;
-ms-transform:translateX(-185px) !important;
-o-transform:translateX(-185px) !important;
transform:translateX(-185px) !important;
}
.menu li:nth-child(3).selected ~ li:last-child {
-webkit-transform:translateX(-185px);
-moz-transform:translateX(-185px);
-ms-transform:translateX(-185px);
-o-transform:translateX(-185px);
transform:translateX(-185px);
}
.menu li:nth-child(4):hover ~ li:last-child {
-webkit-transform:translateX(-90px) !important;
-moz-transform:translateX(-90px) !important;
-ms-transform:translateX(-90px) !important;
-o-transform:translateX(-90px) !important;
transform:translateX(-90px) !important;
}
.menu li:nth-child(4).selected ~ li:last-child {
-webkit-transform:translateX(-90px);
-moz-transform:translateX(-90px);
-ms-transform:translateX(-90px);
-o-transform:translateX(-90px);
transform:translateX(-90px);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="menubox">
<ul class="menu">
<li class="selected">
<a href="#">
First
</a>
</li>
<li>
<a href="#">
Second
</a>
</li>
<li>
<a href="#">
Third
</a>
</li>
<li>
<a href="#">
Forth
</a>
</li>
<li></li>
</ul>
</div>
</body>
</html>
I am trying to load a line of social icons and then underneath that a line of menu items.
The alignment is not 100% right-aligned and in IE. Instead, the menu items get shoved all the way over to the left.
The ideal look on all browsers should be :
Code in a bootply
I'm using bootstrap 2.2.2
HTML:
<div class="row-fluid" id="top-header" style="background: #fff url(http://www.inter-active.co.za/images/background-top.jpg) top center;">
<!-- Navigation -->
<div class="sticky-wrapper" id="navigation-sticky-wrapper" style="height: 108px;">
<div class="navbar navbar-fixed-top" id="navigation">
<div class="container no-padding">
<div id="logo">
<img src="images/logo.png">
</div>
<div class="navbar-inner">
<a class="show-menu" data-target=".nav-collapse" data-toggle="collapse">
<span class="show-menu-bar"></span>
</a>
<div class="nav-collapse collapse">
<ul class="social">
<li class="social"><img alt="" src="http://www.inter-active.co.za/images/twitter.png" ></li>
<li class="social"><img alt="" src="http://www.inter-active.co.za/images/linkedin.png"></li>
<li class="social"><img alt="" src="http://www.inter-active.co.za/images/facebook.png"></li>
</ul>
<br>
<ul class="nav">
<li class="menu"><a class="colapse-menu1" href="#home">Home</a></li>
<li class="menu"><a class="colapse-menu1" href="#sectionA">About Us</a></li>
<li class="menu"><a class="colapse-menu1" href="#solutions">Solutions</a></li>
<li class="menu"><a class="colapse-menu1" href="#news">News</a></li>
<li class="menu"><a class="colapse-menu1" href="#contact-parallax">Careers</a></li>
<li class="menu"><a class="colapse-menu1" href="#contact">Contact Us</a></li>
</ul>
</div>
</div>
</div>
</div>
</div><!--/Navigation -->
</div>
CSS:
#logo {
width:180px;
height:100px;
padding:4px;
position:absolute;
}
#navigation-sticky-wrapper {
height:45px;
}
ul.socials-icons-top li {
width:35px;
height:35px;
display:inline-block
}
ul.socials-icons-top li a {
opacity:0.5;
transition:all 0.3s ease 0s;
-moz-transition:all 0.3s ease 0s;
-webkit-transition:all 0.3s ease 0s;
-o-transition:all 0.3s ease 0s;
}
ul.socials-icons-top li a:hover {
opacity:1;
}
#navigation-sticky-wrapper {
height:120px;
}
.is-sticky {
background-color:#fff;
width:100%;
height:121px;
background: #fff url(../images/background-top.jpg) top center;
width:100%;
}
.navbar-fixed-top .navbar-inner, .navbar-static-top .navbar-inner {
float:right;
margin-right:20px;
}
.navbar-inner {
box-shadow: none !important;
min-height: 45px;
line-height: 20px !important;
transition: all 0.3s ease-out 0s;
border-bottom: none !important;
padding-left: 10px !important;
padding-right: 10px !important;
background: transparent;
margin-top: 55px;
}
.navbar {
position: relative;
float:right;
padding 0 20px;
width:100%
}
li.social {
width:32px;
height:32px;
display:inline-block;
}
ul.social {
float:right;
margin-right:250px;
margin-bottom:2px;
}
.navbar .nav {
width:960px;
text-align:center;
margin: 0 10px 10px 0;
}
.navbar .nav > li {
float:none;
display:inline-block;
width:auto;
}
.navbar .nav > li.menu {
margin-right:5px;
margin-top:5px;
}
.navbar .nav > li > a {
font-family:'Calibri', 'Arial', sans-serif;
text-transform:uppercase;
font-weight:400;
font-size:14px;
color: #e76f25;
display: block;
transition: all 0.3s ease-out 0s;
line-height: 14px;
text-shadow: none;
height:16px;
padding: 0px;
}
ul.menu>li:last-child a {
border:none;
}
.navbar .nav > .active > a, .navbar .nav > .active > a:hover, .navbar .nav > .active > a:focus {
background: none;
box-shadow: none;
color: #222222;
height: 100%;
transition: all 0.3s ease-out 0s;
}
.navbar .nav > li > a:focus, .navbar .nav > li > a:hover {
color: #333;
text-decoration: none;
height: 100%;
transition: all 0.3s ease-out 0s;
}
.navbar .show-menu {
float: right;
width:30px;
margin: 7px 30px 7px 10px;
height: 31px;
padding:2px;
background:url(../images/responsive-menu.png) no-repeat 2px 2px;
background-size:30px 30px;
cursor:pointer;
border-radius:3px;
opacity:0.7;
display:none
}
.navbar .show-menu:hover {
opacity:1;
}
You have added,
a. 250px of right margin for the ul that has the class 'social'.
Figure - 1
b. And 10px of right margin for nav beneath social.
Figure - 2
To align that you need to set the text-align to right add 240px [a - b] of padding-right for nav.
Here is the CSS Code;
.navbar .nav {
margin: 0 10px 10px 0;
padding-right: 240px; /** 250px - 10px **/
text-align: right; /**/
width: 960px;
}
And additionally, there is 5px of right margin for each li in ul has a class of nav. This makes the menu links to be offset to left by 5px.
To fix that you need to add this block of CSS code;
.navbar .nav > li:last-child {
margin-right: 0;
}
Hope this will help. [This is my first Stackoverflow answer ;)]
I was wondering how, in this example, it is possible to have a gap between the menu item and the list.
This is the CSS code for the demo
#colorNav > ul{
width: 450px; /* Increase when adding more menu items */
margin:0 auto;
}
#colorNav > ul > li{ /* will style only the top level li */
list-style: none;
box-shadow: 0 0 10px rgba(100, 100, 100, 0.2) inset,1px 1px 1px #CCC;
display: inline-block;
line-height: 1;
margin: 1px;
border-radius: 3px;
position:relative;
}
#colorNav > ul > li > a{
color:inherit;
text-decoration:none !important;
font-size:24px;
padding: 25px;
}
#colorNav li ul{
position:absolute;
list-style:none;
text-align:center;
width:180px;
left:50%;
margin-left:-90px;
top:70px;
font:bold 12px 'Open Sans Condensed', sans-serif;
/* This is important for the show/hide CSS animation */
max-height:0px;
overflow:hidden;
-webkit-transition:max-height 0.4s linear;
-moz-transition:max-height 0.4s linear;
transition:max-height 0.4s linear;
}
#colorNav li ul li{
background-color:#313131;
}
#colorNav li ul li a{
padding:12px;
color:#fff !important;
text-decoration:none !important;
display:block;
}
#colorNav li ul li:nth-child(odd){ /* zebra stripes */
background-color:#363636;
}
#colorNav li ul li:hover{
background-color:#444;
}
#colorNav li ul li:first-child{
border-radius:3px 3px 0 0;
margin-top:25px;
position:relative;
}
#colorNav li ul li:first-child:before{ /* the pointer tip */
content:'';
position:absolute;
width:1px;
height:1px;
border:5px solid transparent;
border-bottom-color:#313131;
left:50%;
top:-10px;
margin-left:-5px;
}
#colorNav li ul li:last-child{
border-bottom-left-radius:3px;
border-bottom-right-radius:3px;
}
/* This will trigger the CSS */
/* transition animation on hover */
#colorNav li:hover ul{
max-height:200px; /* Increase when adding more dropdown items */
}
Here is the link:
http://demo.tutorialzine.com/2012/10/css3-dropdown-menu/
#colorNav li ul li:first-child {
margin-top: 25px;
}
Is what is creating the gap.
So I've hacked up this CSS menu tutorial and I'm almost done with customizing it, however I'm having 2 issues. Whenever I go over my "About" menu that contains two additional list links the transition works but then the content is shifted over to the left and fades out. The second is, i'm trying to have the bottom border slide up using CSS transition but it simply fades the color in. I've tried changing height, margin-bottom, bottom but no dice. I've attached the code and fiddle
HTML
<div id='cssmenu'>
<ul>
<li><a href='#'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>About Us</span></a>
<ul>
<li class='has-sub'><a href='#'><span>The School</span></a>
</li>
<li class='has-sub'><a href='#'><span>Instructors</span></a>
</li>
</ul>
</li>
<li><a href='#'><span>Classes</span></a></li>
<li><a href='#'><span>Schedule</span></a></li>
<li><a href='#'><span>News</span></a></li>
<li><a href='#'><span>Programs</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
CSS
a {
-webkit-transition: all 0.2s linear 0.2s;
-moz-transition: all 0.2s linear 0.2s;
-ms-transition: all 0.2s linear 0.2s;
-o-transition: all 0.2s linear 0.2s;
transition: all 0.2s linear 0.2s;}
#cssmenu { width: 840px; padding: 0; margin: 0; border: 0; }
#cssmenu ul, #cssmenu li { list-style: none; margin: 0; padding: 0; }
#cssmenu ul { position: relative; z-index: 597; }
#cssmenu ul li { text-align:center; width: 120px; float: left; min-height: 1px; vertical-align: middle; }
#cssmenu ul li.hover, #cssmenu ul li:hover { position: relative; z-index: 599; cursor: default; }
#cssmenu ul ul { visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; }
#cssmenu ul ul li { float: none; width: 200px; }
#cssmenu ul li:hover > ul { visibility: visible; }
#cssmenu ul ul li { bottom: 100; left: 0; margin-top: 0; font-weight: normal; }
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }
#cssmenu { background: #000; font-family: 'Oxygen Mono', Tahoma, Arial, sans-serif; font-size: 12px; }
#cssmenu > ul { *display: inline-block; }
#cssmenu:after, #cssmenu ul:after { display: block; clear: both; }
#cssmenu ul ul a {background: #333;color: #FFF; border: 1px solid #fff; border-top: 0 none; line-height: 150%; padding: 16px 20px; }
#cssmenu ul ul li { position: relative; }
#cssmenu ul ul li:nth-child(1) > a { background: #333; border-bottom: 1px solid #FFF }
#cssmenu ul ul li:nth-child(1) > a:hover { color: #fff; background: #333}
#cssmenu ul ul li:nth-child(2) > a { background: #333; border-bottom: 1px solid #FFF;}
#cssmenu ul ul li:nth-child(2) > a:hover { color: #fff; background: #333; }
#cssmenu ul li:nth-child(1) > a { border-bottom: 5px solid #fff; }
#cssmenu ul li:nth-child(2) > a { border-bottom: 5px solid #ff6; }
#cssmenu ul li:nth-child(3) > a { border-bottom: 5px solid #f60; }
#cssmenu ul li:nth-child(4) > a { border-bottom: 5px solid #00f; }
#cssmenu ul li:nth-child(5) > a { border-bottom: 5px solid #0c6; }
#cssmenu ul li:nth-child(6) > a { border-bottom: 5px solid #63c; }
#cssmenu ul li:nth-child(7) > a { border-bottom: 5px solid #f00; }
#cssmenu ul li:nth-child(1) > a:hover { color: #000; background: #fff; }
#cssmenu ul li:nth-child(2) > a:hover { color: #000; background: #ff6; }
#cssmenu ul li:nth-child(3) > a:hover { background: #f60; }
#cssmenu ul li:nth-child(4) > a:hover { background: #00f; }
#cssmenu ul li:nth-child(5) > a:hover { background: #0c6; }
#cssmenu ul li:nth-child(6) > a:hover { background: #63c; }
#cssmenu ul li:nth-child(7) > a:hover { background: #f00; }
#cssmenu ul ul li.has-sub > a:after {position: absolute;top: 50%;right: 15px;margin-top: -8px; }
#cssmenu ul li.has-sub > a:after { margin-left: 5px; }
#cssmenu a { background: #000; color: #fff;padding: 0 20px; line-height: 45px; }
Try adding position: relative; to #cssmenu ul li. That will fix your issue with the sub-menu floating off to the left.
As for generating the effect of the color rising from the bottom, you could create a absolutely positioned <div> inside the <li> with a starting height of 5px and increase it to cover the entire box once you hover.
EDIT
Here is an example fiddle. http://jsfiddle.net/bbZS8/
I've only incorperated the effect on the second tab, (About Us).
#yellow-test
{
position: absolute;
bottom: -5px;
left: 0;
height: 5px;
width: 100%;
background-color: #FF6;
color: #FF6;
overflow: hidden;
line-height: 45px;
-webkit-transition: height .25s ease;
-moz-transition: height .25s ease;
-o-transition: height .25s ease;
transition: height .25s ease;
}
#cssmenu ul li:hover > div
{
height: 50px;
color: #000;
}
It's not perfect, but gives a good starting point to beginning tweaking.