Change navigation to expand left - html

Navigation bar presently drops down, 1st sub menu expands left, 2nd sub menu expands right so that it's on top of the primary menu. Trying to get the 2nd sub menu to continue expanding left, but any tweaks I make don't change it. Tried to get the ul last child to pull right without success, would appreciate any help. Here's the code I've currently got.
HTML:
<li {{#id}}id="{{id}}"{{/id}}
class="wsite-menu-subitem-wrap {{#is_current}}wsite-nav-current{{/is_current}}"
>
<a
{{^nonclickable}}
{{^nav_menu}}
href="{{url}}"
{{/nav_menu}}
{{/nonclickable}}
{{#target}}
target="{{target}}"
{{/target}}
class="wsite-menu-subitem"
>
<span class="wsite-menu-title">
{{{title_html}}}
</span>{{#has_children}}<span class="wsite-menu-arrow">></span>{{/has_children}}
</a>
{{#has_children}}{{> navigation/flyout/list}}{{/has_children}}
<div class="wsite-menu-wrap" style="display:none">
<ul class="wsite-menu">
{{#children}}{{> navigation/flyout/item}}{{/children}}
</ul>
</div>
CSS:
/* Navigation Menu*/
#nav {position: relative;}
#nav ul {
text-align: right;
overflow: hidden;
}
#nav ul li {
list-style: none;
display: inline-block;
}
#nav ul li a {
display: block;
color: #8e8e8e;
padding: 30px 15px;
font-size: 14px;
text-transform: uppercase;
-webkit-transition: all 240ms linear;
-moz-transition: all 240ms linear;
-o-transition: all 240ms linear;
-ms-transition: all 240ms linear;
transition: all 240ms linear;
}
.minimize #nav ul li a {
padding: 15px;
}
#nav > ul li:first-child a {
padding-left: 30px !important;
}
#nav > ul li:last-child a {
padding-right: 0 !important;
}
#nav ul li#active a,
#nav ul li a:hover {
color: #primary;
text-decoration:none;
border: 0;
}
#mobile-nav, #mobile-input, #nav-trigger, #mobile-cart {
display: none;
}
/* Navigation Submenu*/
#wsite-menus {
position: relative;
z-index: 14;
}
#wsite-menus .wsite-menu {
padding: 10px 0;
background: #headerBg;
-webkit-box-shadow: 0px 0px 3px rgba(99, 99, 99, .1);
box-shadow: 0px 0px 3px rgba(99, 99, 99, .1);
}
#wsite-menus > .wsite-menu-wrap > .wsite-menu .wsite-menu-wrap {
position: absolute !important;
top: 0 !important;
margin-top: -10px !important;
}
#wsite-menus .wsite-menu li a {
font-family: 'Roboto', sans-serif;
color: #8e8e8e;
background: transparent !important;
font-size:13px;
text-transform: uppercase;
border: 0;
padding: 10px 20px;
}
#wsite-menus .wsite-menu li a > span {
padding: 0;
}
#wsite-menus .wsite-menu li a:hover {
color: #primary;
}
#wsite-menus .wsite-menu-arrow {
right: 20px;
width: 10px;
overflow: hidden;
}
#wsite-menus .wsite-menu-arrow:before {
display: inline-block;
content: '\25b6';
font-size: 75%;
vertical-align: top;
line-height: 1.5;
}

Try setting the menu's container element to display: flex; and flex-direction: column;. This way child elements will never be one next to the other.
Edit:
Forget the flex.
I'll suppose you need to put your nav to the right (that's why you want submenus to the left), and you need submenus to display one at a time.
Assuming that, I've made an example so you can see it working.
Note: Just check the commented style, other things are just visuals to match your context and to be easy to scan.
* {
margin: 0;
padding: 0;
}
#root {
display: flex;
}
nav {
margin-left: auto;
margin-right: 100px;
background-color: rgb(30, 30, 30);
color: white;
width: 160px;
}
li {
list-style: none;
padding: 4px;
}
li:hover {
background-color: rgb(90, 90, 90);
}
a {
cursor: pointer;
}
/* dropdown box */
.dropdown {
position: relative;
}
/* dropdown button, it's just a span,
you can use whatever you want */
.dropdown .dropdown_btn {}
/* dropdown content default */
.dropdown .dropdown-content {
display: none;
position: absolute;
z-index: 1;
top: 0;
/* "left -100%" gives same result as "right: 100%"*/
left: -100%;
/* keep size to mach the "left -100%" */
min-width: 100%;
background-color: rgb(60, 60, 60);
}
/* while mouse hover, content will display */
.dropdown:hover .dropdown-content {
display: block;
}
<div id="root">
<nav>
<ul>
<li><a>Item 1</a></li>
<li class="dropdown">
<span class="dropdown-btn">Item 2 / Drop A</span>
<ul class="dropdown-content">
<li><a>Drop A Item 1</a></li>
<li><a>Drop A Item 2</a></li>
</ul>
</li>
<li class="dropdown">
<span class="dropdown-btn">Item 3 / Drop B</span>
<ul class="dropdown-content">
<li><a>Drop B Item 1</a></li>
<li><a>Drop B Item 2</a></li>
</ul>
</li>
<li><a>Item 4</a></li>
</ul>
</nav>
</div>

Related

adding submenu ruins my navigation ,anyone?

now I am finally got my navbar centered I have gotten a submenu in my navbar
now and I am trying to get it to work but all my links are just ruined :-/
so hope someone could explain to me why it doesnt want to work on the way I am doing it?
I want to keep the style of my navbar, and I am currently playing around with the css to get
my submenu working but it keeps ruining it :-/.
also when adding display:inline; to my .topnav ul it is not centered anymore grr ,
I have watched a video but even that would not work with my navbar.
I know I am doing something wrong but what ??
(can be a litle messy just cause i seperated the codes for testing sorry for that!)
/*Topnav*/
.topnav {
width: 100%;
opacity: 1;
background-color: rgba(255,255,255,0.6);
margin-bottom: 10px;
padding: 5px 0px 5px 0;
border-bottom: dotted #66A761;
border-top: dotted #66A761;
position:relative;
}
.topnav ul {
text-align: center;
}
.topnav ul li {
display: inline;
margin-left: 15px;
}
.topnav a {
font-size: 20px;
font-weight: bold;
text-decoration: none;
}
.topnav a:visited {
color: #FFF;
}
.topnav a:link {
color :#9F257D;
}
.topnav a:hover {
color: #66A761;
}
.topnav input {
float: right;
padding: 3px;
margin: 0 5px;
position: absolute;
right: 20px;
}
/*submenu testing*/
.topnav ul li ul li {
display: none;
}
.topnav ul li:hover ul li {
display: block;
}
<!--Topnav-->
<div class="topnav">
<nav>
<ul>
<li>recepten
<ul>
<li>lactosevrij</li>
<li>suikervrij</li>
<li>glutenvrij</li>
</ul>
</li>
<li>varianten
<ul>
<li>basis</li>
<li>standaard</li>
<li>luxe</li>
</ul>
</li>
<li>contact</li>
<li>over ons</li>
<input type="text" style="right:0" placeholder="Search..">
</ul>
</nav>
</div>
.topnav li {
position:relative;
}
.topnav li ul {
position: absolute;
top:25px;
left:0px;
background-color: #fff;
}
If the intention is that these sub menus work as dropdown you might want to set their positioning to absolute, but note that you have to make the wrapper element relative or else it might take the viewport as anchor.
It's not entirely clear what you mean but it sounds like you want a horizontal nav with dropdown sub-menu items.
E.G:
/*Topnav*/
.topnav {
width: 100%;
opacity: 1;
background-color: rgba(255, 255, 255, 0.6);
margin-bottom: 10px;
padding: 5px 0px 5px 0;
border-bottom: dotted #66A761;
border-top: dotted #66A761;
position: relative;
}
.topnav ul {
text-align: center;
display: flex;
justify-content:space-between;
}
.topnav ul li {
display: inline-block;
margin: 0 7px;
padding: 0;
text-indent: 0;
position: relative;
}
.topnav ul li ul {
display: block;
position: absolute;
top: 100%;
left: -100px;
right: -100px;
margin: 0;
padding: 0;
}
.topnav ul li ul li {
display: block;
margin: 0;
padding: 0;
text-indent: 0;
}
.topnav a {
font-size: 20px;
font-weight: bold;
text-decoration: none;
}
.topnav a:visited {
color: #FFF;
}
.topnav a:link {
color: #9F257D;
}
.topnav a:hover {
color: #66A761;
}
.topnav input {
padding: 3px;
margin: 0 5px;
}
/*submenu testing*/
.topnav ul li ul li {
display: none;
}
.topnav ul li:hover ul li {
display: block;
}
<!--Topnav-->
<div class="topnav">
<nav>
<ul>
<li>recepten
<ul>
<li>lactosevrij</li>
<li>suikervrij</li>
<li>glutenvrij</li>
</ul>
</li>
<li>varianten
<ul>
<li>basis</li>
<li>standaard</li>
<li>luxe</li>
</ul>
</li>
<li>contact</li>
<li>over ons</li>
<input type="text" placeholder="Search..">
</ul>
</nav>
</div>
i changed the whole thing again and got it to react only got 2 problems with it
1 i can only get on the first link in the submenu, as soon as i slide down with my cursor it just closes before i hit my other link/links. (while in the snippet it works)
2 cant center my links in the middle under my logo on the page as it is , the spaces between it is perfect.
/*Topnav*/
.topnav {
width: 100%;
opacity: 1;
background-color: rgba(255, 255, 255, 0.6);
margin-bottom: 10px;
padding: 5px 0px 5px 0;
border-bottom: dotted #66A761;
border-top: dotted #66A761;
position: relative;
}
.topnav ul {
display: inline;
text-align: left;
}
.topnav ul li {
display: inline-block;
margin: 0 7px;
padding: 0;
text-indent: 0;
position: relative;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.topnav a {
font-size: 20px;
font-weight: bold;
text-decoration: none;
}
.topnav a:visited {
color: #FF00E0;
}
.topnav a:link {
color: #9F257D;
}
.topnav a:hover {
color: #66A761;
}
.topnav input {
float: right;
padding: 3px;
margin: 0 5px;
position: absolute;
right: 20px;
}
/*submenu testing*/
.topnav ul li ul {
display: block;
position: absolute;
background-color: rgba(255, 255, 255, 0.6);
padding: 5px 5px;
}
.topnav ul li:hover ul li {
display: block;
}
.topnav ul li ul li {
display: none;
}
<div class="topnav">
<nav>
<ul>
<li>recepten
<ul>
<li>lactosevrij</li>
<li>suikervrij</li>
<li>glutenvrij</li>
</ul>
</li>
<li>varianten
<ul>
<li>basis</li>
<li>standaard</li>
<li>luxe</li>
</ul>
</li>
<li>contact</li>
<li>over ons</li>
<input type="text" style="right:0" placeholder="Search..">
</ul>
</nav>
</div>

I need help in fixing my drop down menu from moving when showing <li>

The Problem:
Look at Offers and the li:
After putting position: absolute
Current vs What I want to achieve
How to make my drop down menu so that when I hover on "Offers" the text doesn't move to the left? I would also like to decrease the width of the li as it is too big for me.
I have tried changing the display: property and putting spaces before and after the word "Offers" in HTML. The spaces worked but I didnt like it because the Offers will just look like having more space than the other options.
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul li ul li {
display: none; /*So li dont show up unless hover */
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
I want to dropdown menu to not move when the li is shown in the Offers. And I would like to decrease the width of black background of the li
That's because the sub menu is taking a place and make its parent li wider.
A possible solution is to set the ul child position: absolute so it will not take a place.
Like this:
.menu ul ul {
position: absolute;
}
Live example:
body {
background: url(https://cdn.pixabay.com/photo/2017/08/30/01/05/milky-way-2695569_960_720.jpg) 0 0;
background-size: cover;
}
.nav {
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 80px;
}
.menu {
float: right;
line-height: 80px;
margin: 0 9em;
text-align: center;
font-family: "Proxima Nova";
text-transform: uppercase;
font-weight: bolder;
letter-spacing: 0px;
}
.menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
.menu ul li {
text-align: center;
list-style: none;
display: inline-table;
position: relative;
}
.menu ul li a {
text-decoration: none;
color: white;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
transition: all .3s ease-in-out;
}
.menu ul li a:hover {
color: orange;
}
.menu ul ul {
position: absolute;
width: 100%;
}
.menu ul li ul li {
display: none;
/*So li dont show up unless hover */
}
.menu ul li ul li a {
padding: 0;
text-align: center;
}
.menu ul li:hover ul li {
transition: all .3s ease;
display: block;
background: rgba(0, 0, 0, .6);
}
ul li:nth-child(5) a {
color: white;
border: 1px solid orange;
padding: 10px 20px;
border-radius: 4px;
background-color: none;
transition: all 1s ease-out;
}
ul li:nth-child(5) a:hover {
transition: all .5s ease-in;
background: rgba(204, 204, 204, 0.5);
color: orange;
}
<div class="nav">
<div class="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Offers
<ul>
<li>Packages</li>
<li>Services</li>
<li>Promos</li>
</ul>
</li>
<li>Location</li>
<li>Contact</li>
</ul>
</div>
</div>
The problem lies with the min-content size of the list items in the drop down, which are larger than the size of the parent list items in the top menu.
e.g. 'packages' renders at 120px whereas 'offers' is 98px.
The simplest solution is to set a max-width for all the list items based on the max-content size of the longest word (not very dynamic though).
Otherwise, use position:absolute to layout the sub menu as in this example:
https://codepen.io/skippingredpanda/pen/xNrxVg
Is simple, use:
.menu li { position: relative; } .menu li ul { position: absolute; top: your horizontal nav height; left: 0;}
And also you have a mistake in code, must be like this:
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>
Link 3
<ul>
<li>SubLink 1</li>
<li>SubLink 2</li>
<li>SubLink 3</li>
<li>SubLink 4</li>
</ul>
</li>
<li>Link 4</li>
</ul>
ul li {position: relative;}
ul li ul {position: absolute; display: none;}
ul li:hover ul {display: block;}

How do I retain hover state on parent navigation element while moving your mouse to the sub menu?

I'm trying to add a bit of spacing between my main menu element and sub menu element.
.dropdown-menu{
margin-top:10px;
}
After adding that the sub-menu is placed where I want it but hovering over "Harry Potter Books" and then trying to mouse from that to the sub-menu, the sub-menu disappears.
I want to be able to hover over the main menu item and be able to mouse over to the sub menu.
Please see this codepen, I am using Bootstrap to implement the base menu styles.
https://codepen.io/anon/pen/ErVEZj?editors=11000#0
Let me know if there are any other pieces of information I can provide.
You should make the .navbar-nav>li>a (the thing you are hovering) take up the full height of the navbar since you want the dropdown menu below the navbar.
To easily do this with your code simply move the 10px of margin top and bottom from the .navbar-nav to padding top and bottom of the .navbar-nav>li>a. Then you can remove that margin-top: 10px from the dropdown menu that creates that anti-hovering gap.
/*Navbar styles*/
.nav-element {
color: white;
}
.navbar-nav {
margin-left: 20px !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
}
.navbar-nav>li>a {
padding-right: 20px !important;
padding-left: 20px !important;
padding-top: 15px !important;
padding-bottom: 15px !important;
color: white !important;
transition: all 0.5s ease;
}
#nav:hover>#nav-details {
display: block;
background-color: lightgrey;
}
/*Divider style for sub-menu */
.divider {
height: 1px;
margin: 9px 20px;
overflow: hidden;
background-color: #e5e5e5;
}
.dropdown-menu {}
.navbar-nav>li {
margin-top: 5px;
}
/*these css blocks contain style for the arrow on the sub-menu*/
.dropdown-menu:after,
.dropdown-menu:before {
bottom: 100%;
left: 80px;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
margin-top: 10px;
}
.dropdown-menu:after {
border-color: rgba(211, 211, 211, 0);
border-bottom-color: #D3D3D3;
border-width: 10px;
margin-left: -10px;
margin-top: 10px;
}
.dropdown-menu:before {
border-color: rgba(0, 0, 0, 0);
border-bottom-color: #;
border-width: 13px;
margin-left: -13px;
margin-top: 10px;
}
/*styles for list elements and hover logic */
li {
color: #fff;
display: block;
float: left;
position: relative;
text-decoration: none;
transition-duration: 0.5s;
}
li span a {
color: #fff;
}
li:hover>a:after {
background: orangered;
}
ul li ul {
visibility: hidden;
opacity: 0;
position: absolute;
transition: all 0.5s ease;
left: 0;
display: none;
}
ul li:hover>ul,
ul li>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li:hover>ul,
/*maintain hover state of parent list in sub menus*/
ul li:focus-within>ul,
ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
ul li ul li {
clear: both;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav id="myNavbar" class="navbar navbar-default" role="navigation" style="background-color:royalblue;">
<div class="container">
<div class="navbar-collapse" id="navbarCollapse" style="background-color:royalblue;">
<ul class="nav navbar-nav">
<li id="nav" class="nav-element" aria-haspopup="true">
<a>Harry Potter Books</a>
<ul id="nav-details" aria-label="submenu" class="dropdown-menu sub-menu">
<li>Sorcerer's Stone</li>
<li class="divider"></li>
<li>Chamber of Secrets</li>
<li class="divider"></li>
<li>Deathly Hallows</li>
<li class="divider"></li>
<li>Goblet of Fire</li>
</ul>
</li>
<li class="nav-element" id="ltc-program-nav">
<a>Books Better than Harry Potter</a>
</li>
<li class="nav-element" id="ApplyNowTopLevel">
<a>Another Funny Link</a>
</li>
</ul>
</div>
</div>
</nav>

Delaying hover effect for menu

I want to use this style
Site > Then choose the Zerus theme.
The CSS for Zerus is as follows:
#charset "utf-8";
/* CSS Document */
#import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600');
/* Fonts */
body {
font-family: 'Open Sans', sans-serif;
}
h1, h2, h3, h4, h5, h6, #content a, ul.lw-hmenu a, .lw-hmenu li span.nav-header, #lw-topnav ul a, #lw-topnav ul li span.nav-header {
font-weight: 600;
}
#content a::after {
content: "→";
padding-left: 5px;
}
#content div.pagination ul li a::after {
content: "";
padding-left: 0;
}
/* End Fonts */
/* Colors */
:root{
--primary: #24b47e;
--accent: #6772e5;
--accent2: #b76ac4;
--ux: rgba(255, 255, 255, 0.95);
--ux-border: #6b7c93;
}
.lw_svg_logo {
fill: var(--primary);
}
#masterPage {
background-color:#F6F9FC;
}
#contentPage {
background-color: #F6F9FC;
}
body {
color:#6b7c93;
}
a, span.nav-header {
color: var(--accent);
}
/* End Colors */
#media screen and (min-width: 768px) {
#lw-topnav {
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3);
border-bottom: 9px solid var(--ux-border);
}
#lw-topnav ul>li:hover {
background-color: rgba(0, 0, 0, 0.05);
}
#lw-topnav ul li ul {
border-radius: 15px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.5);
margin-top:15px !important;
}
#lw-topnav ul li ul::before {
display:block;
content: "";
width:20px;
height:20px;
background-color: var(--ux);
position:relative;
left:50%;
margin-top:5px;
transform: translateX(-50%) rotateZ(45deg);
z-index:1;
top:-15px;
}
#lw-topnav ul li ul::after {
display:block;
content: "";
height:9px;
background-color: var(--ux-border);
z-index:1;
border-bottom-right-radius: 15px;
border-bottom-left-radius: 15px;
}
#lw-topnav ul li ul li ul {
border-radius: 8px;
margin-top: 0px !important;
}
#lw-topnav ul li ul li ul::before {
display:none;
}
#lw-topnav ul>li:hover:after{
content:"";
position:absolute;
left:0;
right:0;
top:0px;
height:120%;
z-index:-1;
}
}
I would like to lower the menu that appears when you hover over the top navigation by about 15px. If I do however, then I can't actually get to the sub-menu because the mouse leaves the <li> that contains the hover effect to make it visible, so the menu disappears.
You can see the effect I want by adding this:
#lw-topnav ul li ul {
margin-top:15px !important;
}
I think this can be achieved by using a transition-delay, but no matter where I put it, it doesn't seem to have any effect. I'd like to avoid using javascript if I have to. Can anyone help on where to add the transition-delay?
Thanks
The problem you have is, that your mouse leaves the <li> of the top list, so the hover-event is not working anymore. You have to seperate the display of the sublist and the area where the list item is considered as "hovered".
These are two things, while you see the list itself, you cannot see the area where the program accepts the item as "hovered".
I created a little example by copying and modifying code from SelfHTML where I point out the problem you face.
If you modify the values I highlighted you see the difference.
<html>
<head>
<style>
nav {
border: 1px solid black;
height: 2em;
padding: 0.8em;
width: 50em;
}
nav ul {
margin: 0;
padding: 0;
text-align: center;
}
nav li {
float: left;
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
/* important here */
nav ul ul {
font: 0/0 serif;
margin-top: 40px; /*this changes the display of the sublist*/
padding: 0;
position: absolute;
top: 0em;
/*change this to shift the space where your cursor stays with the sublist*/
z-index: -1;
-webkit-transition: all 0.5s ease-in;
transition: all 0.5s ease-in;
}
nav ul li:hover ul {
font: inherit;
z-index: auto;
color: red;
}
nav ul ul li {
float: none;
margin-bottom: 0.2em;
}
nav a,
nav span {
background-color: royalblue;
border: 1px solid blue;
border-radius: 10px 10px 0 0;
box-shadow: 0px 5px 10px white inset;
color: gold;
display: block;
font-weight: bold;
margin: 0.6em 0 0 0;
padding: 0.4em;
width: 6.4em;
-webkit-transition: all 0.5s ease-in;
transition: all 0.5s ease-in;
}
nav ul ul a,
nav ul ul span {
border-radius: 10px;
}
nav a:focus,
nav a:hover,
nav span
{
color: royalblue;
background-color: gold;
}
nav a:focus,
nav a:hover {
margin-top: 0;
padding: 1em 0.4em 0.4em;
}
nav ul ul a:hover {
margin: 0.6em 0 0 0;
padding: 0.4em;
}
nav ul ul span {
background-color: maroon;
color: gold;
}
</style>
</head>
<body>
<nav>
<ul>
<li>Seite 1</li>
<li>Seite 2
<ul>
<li>Seite 2a</li>
<li>Seite 2b</li>
</ul>
</li>
<li>Seite 3</li>
<li>Seite 4
<ul>
<li>Seite 4a</li>
<li><span>aktuelle Seite</span></li>
<li>Seite 4c</li>
</ul>
</li>
<li>Seite 5</li>
</ul>
</nav>
</body>
</html>
Make sure that your mouse is always hovering the selected list item by modifying the top:0em to 0 or even below 0. To balance the fact that your menu will move upward, simply adjust the margin-top in the same frame! This all has to happen in the sublist itself nav ul ul and of course with another level of depth if you create a list like that! :)
I fixed it by adding an invisible div behind it.
#lw-topnav ul>li:hover:after{
content:"";
position:absolute;
left:0;
right:0;
top:0px;
height:120%;
z-index:-1;
}
That being said. I think S.M.'s solution is better. I'll play around with it more.

Aligning a dropdown menu in CSS in all browsers

I have a dropdown menu that is generated from WordPress so I do not want to change the HTML of it. i can change the CSS as needed though and I pretty much have ot working as I need it with the exception of an alignment issue with my dropdown menu.
Google Chrome
FireFox
Internet Explorer
From the images above you can see that IE and FIreFox display it the same but Chrome is always different from the 2. My Goal is to get this box to align perfectly with the right of the menu button and then get it to look that way in all 3 of these browsers.
I have extracted the HTML and CSS into a JSFiddle page for testing and playing around with here...
Code View: http://jsfiddle.net/jasondavis/hAb4k/
Full View for viewing the menu: http://jsfiddle.net/jasondavis/hAb4k/embedded/result/
My HTML
<nav id="head-nav-menu" class="nav-main" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<ul id="nav" class="nav nav-pills">
<li class="active menu-home">
Home
</li>
<li class="menu-about">
About
</li>
<li class="menu-projects">
Projects
</li>
<li class="menu-blog">
Blog
</li>
<li class="dropdown menu-services">
<a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="/services/">Services <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="menu-consulting">Consulting</li>
<li class="menu-magento-development">
Magento Development
</li>
<li class="menu-wordpress-development">
WordPress Development
</li>
<li class="menu-sugarcrm-development">
SugarCRM Development
</li>
<li class="menu-web-development">
Web Development
</li>
<li class="menu-seo">
SEO
</li>
</ul>
</li>
<li class="menu-contact">
Contact
</li>
</ul>
</nav>
CSS
body{
background: #40C8F4 !important;
}
nav ul, nav ol {
list-style: none;
list-style-image: none;
}
#head-nav-menu{
float: right;
margin-top: 29px;
}
#head-nav-menu li {
float: left;
position: relative;
padding: 0 2px 0 2px;
}
.nav a {
font-family: 'arial';
font-size: 18px;
padding: 8px 18px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: nowrap;
color: #fff;
opacity: 0.9;
letter-spacing: 1px;
text-decoration: none;
}
.menu-contact a {
border: 2px solid #FFF;
padding: 8px 18px;
transition: 0.05s linear;
-moz-transition: 0.05s linear;
-webkit-transition: 0.05s linear;
}
.nav .menu-contact a:hover {
background-color: #FFF;
color: #797979;
}
#nav ul a {
font-weight: 100;
}
.nav a:hover,
.nav > .active a {
opacity: 1;
background-color: #3DBCE6;
}
.nav > .active li a {
background-color: inherit;
}
.tinynav {
display: none;
width: 100%;
margin-top: .5em;
margin-bottom: .6em;
}
.nav li.button a {
background-color: rgba(255, 255, 255, 0.1);
border: 2px solid #FFF;
border-radius: 4px;
margin-top: 5px;
padding: 8px 18px;
font-family: 'ProximaNova-bold', Helvetica, Arial, sans-serif;
font-weight: normal;
margin-left: 16px;
color: #FFF !important;
}
.nav li.button a:hover {
background-color: #FFF;
opacity: 1;
color: #444 !important;
}
/* ==========================================================================
Main Container General Layout Styles
========================================================================== */
.header-container header {
padding-top: 13px;
padding-bottom: 18px;
}
/* Navigation > Dropdown Menus */
#nav .dropdown-menu,
#nav .children {
display: none;
padding: 0;
position: absolute;
z-index: 99999;
border: 1px solid #86DEFC;
width: 333%;
/*right: 8px;*/
left: -239%;
top: 23px;
background-color: #F2F9FC;
}
#nav .dropdown-menu li {
width: 195px;
float: left;
display: inline-block;
/*width: 50%;*/
}
.nav .dropdown-menu a {
color: #030303;
}
#nav li:hover > ul,
#nav ul li:hover > ul,
.dropdown:hover > ul {
display: inline-block;
-webkit-animation: fadeDown 250ms ease;
-moz-animation: fadeDown 250ms ease;
-ms-animation: fadeDown 250ms ease;
-o-animation: fadeDown 250ms ease;
animation: fadeDown 250ms ease;
background-color: #fff;
color: #000;
border: 1px solid #E9E9E9;
border-top: none;
}
#nav .dropdown-menu ul,
#nav .children ul {
left: 99.75%;
top: -1px;
}
#nav ul li,
#nav ul ul li {
margin-left: 0;
}
#nav ul li:first-child,
#nav ul ul li:first-child {
border-top: none;
}
#nav ul a,
#nav ul ul a {
font-size: 14px;
line-height: 21px;
text-align: left;
padding: 10px;
display: inline-block;
min-width: 125px;
border-bottom: none;
margin-bottom: 0 !important;
width: 100%;
letter-spacing: 1px;
font-family: arial;
}
#nav ul a:hover,
#nav ul ul a:hover {
color: #098EB9 !important;
background: none;
}
#nav ul ul.dropdown-menu a:hover {
width: 100%;
color: #63E924 !important;
border-bottom: none;
}
#nav li.current_page_item ul a,
#nav li.current-menu-parent ul a,
#nav li.current_page_parent ul a {
color: #000;
font-weight: 700;
}
#nav ul li.current-menu-item a {
color: #e9242e !important;
}
#head-nav-menu .nav li:hover a.dropdown-toggle {
background: #fff;
color: #000;
opacity: 1;
border-right: 1px solid #E7E7E7;
}
.nav .dropdown a:hover {
opacity: 1;
background-color: #fff;
}
#nav .dropdown-menu li:hover {
background: #F8F8F8;
}
Give display: block to .nav a
then remove left: 239% of #nav .dropdown-menu and give right: 2px and top: 38px to it.
Here is the edited demo for it.
http://jsfiddle.net/hAb4k/3/