I have a drop down menu and when you hover over an option it shows the submenu, but then when you move the cursor down; sometimes the rest of the menu will hide. I have noticed there is a little bit of space (margin? border?) underneath that I am assuming is the culprit unless someone can tell me differently.
Below is an image to show what I mean; there is a small gap between the two options and I am assuming when you make the cursor go over that point it comes off "hover" and hides it
Any help would be greatly appreciated.
.menu ul { margin = ..;}
The above code makes the margin bigger, however even when it is set to 0 it still seems to be there..
This is my HTML for the menu
<td align="center" bgcolor="#666666">
<div class="menu" align="center">
<ul>
<li>Bar Equipment
<ul>
<li>Tills</li>
<li>Bar Furniture</li>
<li>Bar Sundries</li>
...
</div></td>
This is the Css for the menu class
#charset "utf-8";
* {
margin: 0px; padding: 0px;
}
.menu {
margin: 0px;
text-align: center;
background: #efefef;
padding: 0px;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
background: #efefef;
padding: 0;
list-style: none;
position: relative;
display: inline-table;
margin: 0px;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
}
.menu ul li:hover {
background: #999;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
display: block;
padding: 10px;
color: #757575;
text-decoration:none;
}
.menu ul ul {
background: #efefef;
padding: none;
position: absolute;
top: 100%; /* ?? */
}
.menu ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color:#fff;
display: block;
}
.menu ul ul li a:hover {
background: red;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul ul li a {
padding: 10px;
color: #fff;
}
.menu ul ul ul li a:hover {
background: red; */
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
}
see the jsfiddle: http://jsfiddle.net/p1kuzzdo/
try this css:
#charset "utf-8";
* {
margin: 0px; padding: 0px;
}
.menu {
background: none repeat scroll 0 0 #efefef;
height: 50px;
line-height: 50px;
margin: 0;
padding: 0;
text-align: center;
}
.menu ul ul {
display: none;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
height: 50px;
line-height: 50px;
list-style: outside none none;
margin: 0;
padding: 0;
position: relative;
text-align: center;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
padding: 0 10px;
}
.menu ul li:hover {
background: #999;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
color: #757575;
display: block;
text-decoration: none;
}
.menu ul ul {
background: none repeat scroll 0 0 #efefef;
padding: 0;
position: absolute;
top: 100%;
}
.menu ul ul li {
border-bottom: 0 solid pink;
border-top: 0 solid #6b727c;
float: none;
margin: 0;
padding: 0;
position: relative;
}
.menu ul ul li a {
padding: 10px;
color:#fff;
display: block;
}
.menu ul ul li a:hover {
background: red;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top:0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 0px solid #6b727c;
border-bottom: 0px solid pink;
position: relative;
}
.menu ul ul ul li a {
color: #fff;
}
.menu ul ul ul li a:hover {
background: red; */
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
}
Related
I'm having troubles with my horizontal menu-bar list items overlapping.
So the ul ul li of the nav div elements overlap, what can I do to stop that?
The jsfiddle
CSS:
body, html{
padding: 0px;
margin: 0px;
}
.nav {
font-family: 'PT Sans', sans-serif;
width: 100%;
color: #F5F5F5;
background: #1565c0;
display: flex;
height: 40px;
padding: 0;
margin: 0;
border: 0;
}
.nav ul, .nav ul li, .nav{
list-style: none;
margin: 0;
padding: 0;
border-bottom: 3px solid #0d47a1;
}
.nav ul li{
background: #1565c0;
width:auto;
position: relative;
transition: background 250ms ease-in;
line-height: 40px;
display:block;
}
.nav ul li:hover{
background: #0d47a1;
}
.nav ul ul{
overflow:visible;
position: absolute;
visibility: hidden;
top: 100%;
width: 0%;
}
.nav ul ul li{
border:none;
display:block;
position: absolute;
left:0;
margin:0px;
}
.nav ul li:hover>ul{
visibility: visible;
}
.nav a{
text-decoration: none;
color: inherit;
margin: 0px 20px;
}
.nav ul ul li:last-child{
border-bottom: 3px solid #0d47a1;
}
<div class="nav">
<ul>
<li><a>Hi there</a><ul><li><a>Here is the awesomeness</a></li>
<li><a>Awesome</a></li>
</ul>
</div>
fiddle Here are some modification in your code:
.nav ul ul li {
border: medium none;
display: block;
/*left: 0;*/
margin: 0;
/*position: absolute;*/
}
.nav ul ul {
overflow: visible;
position: absolute;
top: 100%;
visibility: hidden;
/*width: 0;*/
}
you can add below css not to wrap your text in 2 lines:
.nav ul ul {
white-space: nowrap;
}
Try like this Demo
CSS:
.nav ul li > ul {
position: relative;
display:none;
}
.nav ul ul li {
border:none;
display:block;
position: relative;
left:0;
margin:0px;
}
.nav ul li:hover>ul {
display:block;
}
body, html {
padding: 0px;
margin: 0px;
}
.nav {
font-family:'PT Sans', sans-serif;
width: 100%;
color: #F5F5F5;
background: #1565c0;
display: flex;
height: 40px;
padding: 0;
margin: 0;
border: 0;
}
.nav ul, .nav ul li, .nav {
list-style: none;
margin: 0;
padding: 0;
border-bottom: 3px solid #0d47a1;
}
.nav ul li {
background: #1565c0;
width:auto;
position: relative;
transition: background 250ms ease-in;
line-height: 40px;
display:block;
}
.nav ul li:hover {
background: #0d47a1;
}
.nav ul li > ul {
position: relative;
display:none;
}
.nav ul ul li {
border:none;
display:block;
position: relative;
left:0;
margin:0px;
}
.nav ul li:hover>ul {
display:block;
}
.nav a {
text-decoration: none;
color: inherit;
margin: 0px 20px;
}
.nav ul ul li:last-child {
border-bottom: 3px solid #0d47a1;
}
<div class="nav">
<ul>
<li><a>Hi there</a>
<ul>
<li><a>Here is the awesomeness</a>
</li>
<li><a>Awesome</a>
</li>
</ul>
</li>
</ul>
</div>
I have the horizontal menu. I have two problem with this menu are:
when I resize the browser, it will change to responsive menu.
when I open the page in big resolution screen, menu not came in full screen.
I don't need responsive menu.
How to rectify following things:
Each link should equal width
space between the link name and left/right border should equal.
menu should be 100% width.
My code is here:
<div class="menudiv">
<div class="menu">
<ul>
<li><img src="img/img1.png" alt="">Link1</li>
<li><img src="img/img1.png" alt="">Link1</li>
<li><img src="img/img1.png" alt="">Link1</li>
<li><img src="img/img1.png" alt="">Link1</li>
<li><img src="img/img1.png" alt="">Link1</li>
<li><img src="img/img1.png" alt="">Link1</li>
</ul>
</div>
</div>
<style>
.menudiv {
width: 94%;
margin:0 3%;
}
.menu {
font-family: 'Open Sans', sans-serif;
font-size: 14px;
}
.menu ul ul {
display: none;
margin:4px 0 0 0;
}
.menu ul li:hover > ul {
display: block;
}
.menu ul {
background: #646464;
margin: 0;
list-style: none;
position: relative;
padding: 0;
-moz-border-radius: 13px;
-webkit-border-radius: 13px;
}
.menu ul:after {
content: "";
clear: both;
display: block;
}
.menu ul li {
float: left;
border-bottom: 3px solid transparent;
border-right: 1px solid #000;
}
.menu ul li:last-child{
border:none;
}
}
.menu ul li:hover {
background: #111312;
border-bottom: 3px solid #fff;
}
.menu ul li:hover a {
color: #fff;
}
.menu ul li a {
display: block;
padding: 11px 42px;
color: #fff;
text-decoration: none;
}
.menu ul ul {
background: #111312;
padding: 0;
position: absolute;
top: 100%;
}
.menu ul ul li {
float: none;
position: relative;
border-right:none;
}
.menu ul ul li a {
padding: 10px;
color: #000;
display: block;
}
.menu ul ul li a:hover {
background: #111312;
color: #fff;
}
.menu ul ul ul {
position: absolute;
left: 100%;
top: 0;
padding: 0;
}
.menu ul ul ul li {
float: none;
border-top: 1px solid #6b727c;
border-bottom: 1px solid pink;
position: relative;
}
.menu ul ul ul li a {
padding: 10px;
color: #fff;
display: block;
text-decoration: none;
}
.menu ul ul ul li a:hover {
background: #95CEF1;
color: #000;
}
.menu ul ul ul ul {
position: absolute;
left: 100%;
top: 0;
}
.head {
width: 500px;
height: 200px;
background: #789;
}
.foot {
width: 500px;
height: 200px;
background: #123;
}
</style>
You can use display:table, display:table-row and display:table-cell css properties to get what you wanted to achieve.
CSS:
.menu {
display: table;
width:100%;
}
.menu ul {
list-style:none; margin:0 padding:0;
display:table-row
}
.menu ul li{
display:table-cell;
}
.menu ul li > a {
display:block;
padding:2px 4px;
background:#333;
color:#fff;
text-decoration:none;
}
More customization can be done for this type of css structure also. Fiddle link http://jsfiddle.net/ZnRcY/
You can try this
Working Fiddle here
.menudiv {
width: 94%;
margin:0 3%;
-moz-border-radius: 13px;
-webkit-border-radius: 13px; background: #646464;
}
.menu {
font-family: 'Open Sans', sans-serif;
font-size: 14px;
text-align:center;display:table;
width:100%;
}
.menu ul {
margin: 0;
list-style: none;
position: relative;
padding: 0;
display:table-row;
}
.menu ul li {
display:table-cell;
border-bottom: 3px solid transparent;
border-right: 1px solid #000;
}
Good Luck...
i have this css code for my responsive css menu:
nav, ul, li, a {
margin: 0; padding: 0;
}
a {
text-decoration: none;
}
.container {
width: 100%;
margin: 10px auto;
}
.toggleMenu {
display: none;
background: #666;
padding: 10px 15px;
color: #fff;
}
.nav {
list-style: none;
*zoom: 1;
background:#f36f25;
}
.nav:before,.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 9em;
}
.nav a {
padding: 10px 15px;
color:#fff;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-top: 1px solid #104336;
}
.nav > li > .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: right;
}
.nav > li > a {
display: block;
}
.nav li ul {
position: absolute;
left: -9999px;
}
.nav > li.hover > ul {
left: 0;
}
.nav li li.hover ul {
left: 100%;
top: 0;
}
.nav li li a {
display: block;
background: #1d7a62;
position: relative;
z-index:100;
border-top: 1px solid #175e4c;
}
.nav li li li a {
background:#249578;
z-index:200;
border-top: 1px solid #1d7a62;
}
#media screen and (max-width: 768px) {
.active {
display: block;
}
.nav > li {
float: none;
}
.nav > li > .parent {
background-position: 95% 50%;
}
.nav li li .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: 95% 50%;
}
.nav ul {
display: block;
width: 100%;
}
.nav > li.hover > ul , .nav li li.hover ul {
position: static;
}
}
but i cannot get the menu items to align in the centre of the menu/page
here is a fiddle with the full code:
http://jsfiddle.net/5Z2QV/
Is THIS FIDDLE what you want?
If so, then you have to remove float from the lis and add display: inline-block to them. Then you have to add text-align: center to the .nav
.nav {
list-style: none;
background:#f36f25;
text-align: center;
border-top: 1px solid #104336;
}
.nav > li {
display: inline-block;
}
I also removed border-top from the li and put it in the .nav to remove the gaps between lis.
EDIT:
To keep sub-menu items aligned to the left, add this CSS:
.nav li {
text-align: left;
}
EDIT2:
You don't need this adjustMenu() javascript function. You can use media queries. Modify your #media section a bit. Add this style:
.nav {
border-top: none;
}
and replace style for .nav > li with this:
.nav > li {
display: block;
border-top: 1px solid #104336;
}
Also, I noticed that in the small range of resolution, one menu item breaks into new line. To prevent this, you can add this style to the .nav
white-space: nowrap;
overflow: hidden;
Here's the update fiddle: http://jsfiddle.net/5Z2QV/9/
I have a CSS menu using the following CSS.
What is the best way to center the whole menu on the page?
I have tried using another <div> outside <nav> and setting margins but its just aligning left all the time.
nav {
margin: 0 auto;
text-align: center;
border:1px solid black;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
}
nav ul li {
float: left;
}
nav ul li:hover a {
color: #000000;
}
nav ul li a {
display: block;
padding: 10px 15px;
color: #000000;
text-decoration: none;
}
nav ul ul {
border-radius: 0px;
padding: 0;
position: absolute;
}
nav ul ul li {
float: none;
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
position: relative;
}
nav ul ul li a {
color: #000000;
}
nav ul ul li a:hover {
color: #666666;
}
nav ul ul ul {
position: absolute;
top:0;
}
jsfiddle : http://jsfiddle.net/njuVm/
You can center the navigation bar by using the following CSS rules:
nav {
margin: 0 auto;
text-align: center;
border:1px solid black;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
margin: 0; /* << add this */
padding: 0; /* << add this */
display: inline-block; /* << add this */
vertical-align: top; /* << add this */
}
nav ul li {
float: left;
margin: 0; /* << add this */
padding: 0; /* << add this */
}
nav ul li:hover a {
color: #000000;
}
nav ul li a {
display: block;
padding: 10px 15px;
color: #000000;
text-decoration: none;
background-color: pink; /* optional... */
}
nav ul ul {
border-radius: 0px;
padding: 0;
position: absolute;
}
nav ul ul li {
float: none;
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
position: relative;
}
nav ul ul li a {
color: #000000;
}
nav ul ul li a:hover {
color: #666666;
}
nav ul ul ul {
position: absolute;
top:0;
}
See demo at: http://jsfiddle.net/audetwebdesign/DP6Ax/
The key is to set display: inline-block for nav ul, which will allow your text-align: center rule to take effect.
Make sure to zero out margins and paddings on the ul and li elements. Everything else that you did was more or less right, so you should be good.
Instead of floating the li, you can display them as inline-blocks.
Then, they will be centered relatively to the ul because of text-align: center.
Since the ul is as wide as the nav by default, the li will look like centered relatively to the nav.
nav {
text-align: center;
border: 1px solid black;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav > ul > li {
display: inline-block;
}
nav a {
display: block;
padding: 10px 15px;
color: #000000;
text-decoration: none;
}
nav li:hover > ul {
display: block;
}
nav > ul ul {
display: none;
position: absolute;
}
nav > ul ul > li {
border-bottom: 1px solid #000000;
}
nav > ul ul a:hover {
color: #666666;
}
<nav>
<ul>
<li>Add Contact</li>
<li>View Contact</li>
<li>Tickets
<ul>
<li><a>TEST1</a></li>
<li><a>TEST2</a></li>
</ul>
</li>
<li>Invoices</li>
<li>Itemised Calls</li>
</ul>
</nav>
First, when you float the ul's you have to clear the float by adding clear div:
HTML :
<div class="clear"></div>
CSS :
.clear{
clear:both;
}
And for centring the menu you should specify a width of the ul as in example and randomly I have set the width to 560px :
nav ul {
list-style: none;
width : 560px;
margin: 0 auto;
}
Take a Look:
http://jsfiddle.net/njuVm/6/
I've set the DIV height to 54px but for some reason the UL is only about half of that - all the navigation links are way up at the top of the div for some reason.
<div id="menu">
<ul class="left" style="display: none;">
<li id="dashboard"><?php echo $text_dashboard; ?></li>
</u>
</div>
Here's what's in my CSS that I think pertains to this:
#menu {
background: url('../image/menu.png') repeat-x;
position: relative;
z-index: 1;
height: 54px;
clear: both;
padding: 0px 30px;
min-width: 900px;
}
#menu > ul.left {
float: left;
}
#menu > ul.right {
float: right;
}
#menu > ul {
position: relative;
margin: 0;
padding: 0;
}
#menu > ul ul {
list-style: none;
margin: 0;
padding: 0;
background: url('../image/transparent.png');
}
#menu > ul a {
display: block;
text-decoration: none;
}
#menu > ul li {
float: left;
list-style: none;
}
#menu > ul > li + li {
background: url('../image/split.png') center left no-repeat;
}
#menu > ul .top {
padding: 10px 15px 9px 17px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
text-align: center;
}
#menu > ul li ul {
position: absolute;
}
#menu > ul ul li {
padding: 2px;
clear: both;
}
#menu > ul .selected .top {
background: url('../image/selected.png') repeat-x;
color: #FFFFFF;
}
#menu > ul .parent {
background-image: url('../image/arrow-right.png');
background-position: 95% center;
background-repeat:no-repeat;
}
#menu > ul li ul ul {
margin: -29px 0 0 161px;
}
#menu > ul li li a {
padding: 5px;
margin: 1px;
color: #FFFFFF;
width: 147px;
}
#menu > ul li li > a:hover {
margin: 0px;
border: 1px solid #BD4C14;
background-color: #391706;
}
Any idea what needs to be changed to extend the height of the UL like I did the DIV?