I have a menu bar that has three items with drop down menus. When I hover my mouse over the menu bar itself, the drop down menu shows up, but when I move the mouse away to hover over something in the actual drop down menu, it disappears. I assume I'm missing something in my css code, but I'm not sure what. Here's what I have:
body {
background: url(background.jpg);
font-family:Georgia;
margin:10;
padding:10;
}
.main {
width:1000px;
margin:0 auto;
background: #000;
color:#fff;
}
.main > div {
height:200px;
margin:10px;
}
div.bottom {
height:0;
clear:both;
margin:0;
}
.main .head {
height:100px;
color:#fff;
line-height: 100px;
}
h1 {
font-size: 30px;
font-weight: bold;
margin:0;
}
h5 {
color:#000;
}
.main .page {
min-height:500px;
height:auto;
}
.main .foot {
height:70px;
text-align: center;
line-height: 70px;
}
.span_1 {
width:800px;
}
.span_2 {
width:990px;
}
div.menu {
height:50px;
line-height: 50px;
background:#000;
color:#fff;
}
.menu a:link,
.menu a:visited {
color:#000;
text-decoration: none;
padding:0 10px;
}
.menu ul,
.menu li,
.menu h5,
.menu .mega-drop {
list-style:none;
margin: 0;
padding: 10;
background:#fff;
}
.menu li {
position: relative;
}
.menu > ul > li {
float:left;
border-right:solid 1px;
}
.menu > ul > li > ul {
position: absolute;
left:0;
top:60px;
width:400px;
z-index:1;
display:none;
}
.menu > ul > li > .mega-drop {
position: absolute;
left:0;
top:60px;
z-index:1;
width:400px;
display:none;
}
.menu > ul > li > .mega-drop > .mega-drop-column {
float:left;
width:200px;
}
.menu > ul > li > ul > li > ul {
position: absolute;
left:400px;
top:0;
width:400px;
z-index:1;
display:none;
}
.menu li:hover {
background: #3f0;
}
.menu li:hover > ul,
.menu li:hover > .mega-drop {
display: block;
}
you have to do something like this
<div id="menubar"> <- here is your hover to show the menu
<div id="navpoint1">...</div>
<div id="navpoint2">...</div>
<div id="navpoint3">...</div>
...
</div>
now you are "the whole time" hover 'menubar' and the dropdown will not dissappear
This happened to me and tried several methods. I altered the following code and worked a charm! It was strange because it only happened on the index page!!
Was this...
#nav li ul {
width:100%;
margin:0;
padding:0;
display: none;
position: absolute;
top: 100%;
background-color: #39F;
background: rgba(51, 153, 255, .9);
}
Changed to...
#nav li ul {
width:100%;
margin:0;
padding-top:.2em;
display: none;
position: absolute;
top: 100%;
background-color: #39F;
background: rgba(51, 153, 255, .9);
z-index:99999;
}
Related
I'm concluding a design and I'm facing an issue which I'm not familiar with. I'm trying to make a menu expand from hidden to visible over 2 seconds on hover using a transition: height CSS element.
The issue is that the ul is obeying the transition and appearing visible within 2s, however the lis are completely ignoring the transition effect and instantly expanding on hover.
CSS syntax below:
#main_navbar_container{
margin-bottom:0;
background:white;
}
.navbar-collapse {
text-align:center;
}
#menu_container{
width:80%;
float:right;
display:block;
}
#primary_menu{
display:block;
float:left;
width:100%;
}
#primary_menu ul{
list-style: none;
margin: 0;
padding-left: 0;
}
#primary_menu a,
#primary_menu a:visited,
#primary_menu a:link{
color:#ea474b;
font-weight: 600;
display: block;
text-decoration: none;
padding: 15px 20px;
margin:auto;
}
#primary_menu a:hover{
color:#F9690E;
}
#primary_menu li{
float:left;
position:relative;
margin:0
}
#primary_menu ul ul {
box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
border-radius: 4px;
border: 1px solid #dadada;
background: #fff;
color: #8c9398;
float: right;
position: absolute;
top: 3.5em;
right: -999em;
z-index: 99999;
text-align: center
}
#primary_menu ul li:hover > ul {
right: 50%;
margin-right: -100%;
width: 200px;
}
.sub-menu li{
margin:0 15px !important;
}
#primary_menu ul li ul a{
color:#ea474b;
}
#primary_menu ul li ul:hover a{
color:#ea474b;
}
#primary_menu ul li ul li:hover a{
color:#F9690E;
}
#media (max-width: 1200px){
#main_navbar_container .container, #menu_container { width: 100%;}
#menu_container .navbar-collapse { padding: 0;}
#primary_menu{
width:100%;
margin:0;
}
#primary_menu li{
width:100%;
margin:5px 0 0 0;
}
#primary_menu ul li ul {
border-radius: 0 !important;
border-color: transparent !important;
display:hidden;
height:100px;
-webkit-transition: height 2s; /* Safari */
transition: height 2s;
}
#primary_menu ul li:hover{
background:none;
}
#primary_menu ul li:hover a{
font-color:black;
/*\color:rgb(207,0,15);*/
}
#primary_menu ul li:hover ul{
position:initial;
display:block;
background-color:rgb(238,238,238);
width:100%;
padding:0;
margin:0;
height:400px;
}
#primary_menu ul li:hover li:first-of-type{
border-top:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover li:last-of-type{
border-bottom:1px solid rgb(238,238,238);
}
#primary_menu ul li:hover a:link,
#primary_menu ul li:hover a:visited{
color:#ea474b;
}
#menu-home-screen-menu{
margin-left:0;
}
}
Here is a fiddle: http://jsfiddle.net/x15jw967/
A few things help here. First, transition max-height instead of height to allow variation:
#primary_menu ul li ul {
...
max-height:0;
-webkit-transition: max-height 2s;
transition: max-height 2s;
}
#primary_menu ul li:hover ul {
...
max-height: 400px;
}
Then, set overflow to hidden so the outer content doesn't show:
#primary_menu ul li ul {
...
overflow: hidden;
}
Demo
Here's a simplified demo in which the close transition works also. You can add your styling back in and see what breaks it.
I have this css menu with sub items, how can i keep the menu item active (have a different background color) when hovering over the sub items?
current CSS code:
#nav {
background-color:#F36F25;
margin:14px 0 0 0;
width: 100%;
height:35px;
left:0;
}
#nav>li {
float:left;
list-style:none;
}
#nav li:hover ul {
position:absolute;
display:block;
}
#nav li a {
display: inline-block;
padding: 8px;
margin:0;
background: #F36F25;
text-decoration: none;
color: #FFFFFF;
border-right:1px solid #F36F25;
}
#nav li a:hover, #nav li a.active {
background: #666666;
cursor:pointer;
}
#nav li ul {
position:absolute;
display: none;
list-style:none;
margin:0;
}
#nav li ul li {
margin-top:0;
margin-right:0;
margin-bottom:0;
margin-left:-40px;
}
#nav li ul li a {
background-color: #F36F25;
color:#FFFFFF;
border:1px solid #F36F25;
width:145px;
}
#nav li ul li a:hover {
background-color: #666666;
border:1px solid #f36f25;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
here is a fiddle with the fulle code too: http://jsfiddle.net/dumJd/
Try this code here on line 25:
#nav li:hover > a, #nav li a.active {
background: #666666;
cursor:pointer;
}
I'm running into a problem with a CSS submenu I created where the mouse will not highlight the entire submenu bar, but will only highlight an amount relative to the text length.
HTML:
<body>
<div id="page">
<div id="header">
<div>
<ul class="main-nav">
<li>
Menu One
</li>
<li class="nav-primary-middle">
<a href="shops.html" >Shops Listing</a>
<ul class="subnav">
<li>Ice Cream Shop
</li>
<li>Auto Mechanic
</li>
<li>Dentist
</li>
<li>Long Shop Name
</li>
<li>Ace
</li>
</ul>
CSS:
div#page {
width:100%;
}
div#page div#header {
background:url("../images/bg-header.png") no-repeat scroll center bottom transparent;
width:100%;
height:140px;
margin:0 0 90px 0;
}
div#page div#header div {
width:960px;
height:140px;
margin:0 auto;
position:relative;
}
div#page div#header div a.logo {
position:absolute;
left:370px;
top:7px;
display:block;
z-index:999;
}
div#page div#header div ul.navigation {
list-style-type:none;
margin:0;
padding:0;
position:absolute;
top:65px;
}
div#page div#header div ul.navigation li {
float:left;
}
div#page div#header div ul.navigation li.middle {
margin:0 170px 0 0;
}
div#page div#header div ul.navigation li.nav-primary-middle {
margin:0 170px 0 0;
}
div#page div#header div ul.navigation li a {
font-family:'didact_gothicregular';
font-size:16px;
color:#b0b6c4;
text-decoration:none;
padding:0 40px;
}
div#page div#header div ul.navigation li a:hover {
font-family:'didact_gothicregular';
font-size:16px;
color:#5b6a9f;
}
div#page div#header div ul.navigation li a.active {
font-family:'didact_gothicregular';
font-size:16px;
color:#5b6a9f;
}
main-nav {
position: relative;
width: 100%;
height: 67px;
background: #f2f2f2;
}
div#page div#header .subnav {
display: none;
position: absolute;
top: 15px;
left: 150px;
width: 205px;
list-style-type: none;
background: #fff;
margin: 0;
border:solid 2px #eeeeee;
border-radius: 10px;
z-index:0;
padding:0;
}
div#page div#header .subnav li {
display: block;
border-bottom: solid 1px #eeeeee;
width: 100%;
margin:0;
}
div#page div#header .subnav li a {
color: #333;
height:48px;
padding:0px 0;
font-size:13px;
}
div#page div#header .subnav li a:hover {
background:#e3e3e3;
width: 215px;
border-radius: 3px;last
}
div#page div#header .subnav2 {
display: none;
position: absolute;
top: 19px;
left: 735px;
width: 205px;
list-style-type: none;
background: #fff;
margin: 0;
border:solid 2px #eeeeee;
border-radius: 10px;
z-index:0;
padding:0;
}
div#page div#header .subnav2 li {
display: block;
border-bottom: solid 1px #eeeeee;
width: 100%;
margin:0;
}
div#page div#header .subnav2 li a {
color: #333;
height:48px;
padding:0px 0;
font-size:13px;
}
div#page div#header .subnav2 li a:hover {
background:#e3e3e3;
width: 215px;
border-radius: 3px;last
}
div#page div#header li:hover .subnav {
display: block;
}
div#page div#header li:hover .subnav2 {
display: block;
}
div#page div#header div ul.main-nav {
list-style-type:none;
margin:0;
padding:0;
position:absolute;
top:65px;
}
div#page div#header div ul.main-nav li {
float:left;
}
div#page div#header div ul.main-nav li.middle {
margin:0 170px 0 0;
}
div#page div#header div ul.main-nav li.nav-primary-middle {
margin:0 170px 0 0;
}
div#page div#header div ul.main-nav li a {
font-family:'didact_gothicregular';
font-size:16px;
color:#5b6a9f;
text-decoration:none;
padding:0 40px;
}
div#page div#header div ul.main-nav li a:hover {
font-family:'didact_gothicregular';
font-size:16px;
color:#3f4c7b;
}
div#page div#header div ul.main-nav li a.active {
font-family:'didact_gothicregular';
font-size:16px;
color:#3f4c7b;
}
See the image below as an example of "Dentist" not having a full grey highlight for the entire width of the submenu when you mouse over it:
(Edit, oh, I don't have enough rep to post an image. Please see the JSFIDDLE link, select "Shops Listing" and you can see the submenu not highlighting the entire bar.)
![dropdown menu highlight in gray][1]
Please see this *this jsfiddle link.*
Any help is appreciated, thanks.
you can simply remove the background style from your div#page div#header .subnav li a:hover block. Then, add this
div#page div#header .subnav li:hover{
background:#e3e3e3;
}
Demo
Add the rules below to your CSS.
.subnav { overflow: hidden }
.subnav > li > a { display: block }
Check this fiddle. http://jsfiddle.net/q3xR5/
There is a comment called my edit in there. Please note you need to
adjust paddings on your elements.
Hi I cannot figure out how to change the size of the child item of the CSS menu (The parent has an image background, the child should have a background color).
I tried something like:
ul > li > a:hover {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
but it is all mixed with other elements. Can you please help me figure it out?
HTML:
<div id="menu">
<ul>
<li><a id="menu1" href="#">Parent1</a></li>
<li>Parent2
<ul>
<li>Child1</li>
<li>Child2</li>
<li>Child3</li>
</ul>
</li>
<li>Parent3</li>
<li>Parent4</li>
<li>Parent5</li>
</ul>
</div>
CSS:
#menu {
position:absolute;
top:133px;
left:0px;
width:900px;
height:50px;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
/*padding: 5px 15px 5px 15px;*/
background-image: url(../images/menu1.png);
white-space: nowrap;
width:178px;
height:50px;
}
ul li a:hover {
background: #BBBBBB;
}
li:hover ul {
display: block;
position: absolute;
left:0px;
}
li:hover li {
float: left;
font-size: 11px;
}
li:hover a {
background: #3b3b3b;
}
li:hover li a:hover {
background: #CCC;
}
Thank you very much for your help in advance!
Hope following changes will work for you. Here is the fiddle link. Followings are your css chagnes
#menu {
/*position:absolute;
top:0;
left:0px;*/
width:900px;
height:22px;
background-color:#000;
}
ul {
font-family: Arial, Verdana;
font-size: 14px;
line-height:22px;
margin: 0;
padding: 0;
list-style: none;
text-align:center;
}
ul li {
display: block;
float: left;
position:relative;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
/*padding: 5px 15px 5px 15px;*/
background-image: url(../images/menu1.png);
white-space: nowrap;
width:178px;
line-height:22px;
}
ul li:hover a {
background: #BBBBBB;
}
ul li ul {
display: none;
widht:200px;
position:absolute;
left:0;
top:22px;
}
ul li ul li {
float: none;
font-size: 11px;
}
ul li ul li a {
background: #3b3b3b;
background-image:none!important;
}
ul li ul li a:hover {
background: #CCC;
}
ul li:hover ul {
display: block;
position: absolute;
left:0px;
}
To add a background color to your child sub menu:
ul li ul li {
// rules
}
You can also add class to your list items to make it more manageable. For example, you can add a class to the ul of your child menu:
<li>Parent2
<ul class="sub-menu">
<li>Child1</li>
<li>Child2</li>
<li>Child3</li>
</ul>
</li>
Then you can simplify the css to:
.sub-menu li {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
It is good to retain the same width so that you can avoid that weird movement.
Try this
ul li ul li a:hover {
display:block;
background:#000;
float:left;
width:178px;
height:25px;
}
DEMO
I don't know how you want the result to look exactly but you could also use the + selector in your css like this:
ul > li > a:hover+ {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
The + selector as you see after a:hover means that the next element directly after the a:hover-tag will be selected and is this case it will be a ul
You can also specify the element with +ul if you want the ul to be a list and not a flat one like this:
ul > li > a:hover+ul {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
Like this you know that you will only affect the element next to the hovered one
Solution
ul > li:hover > li > a {
display:inline-block;
background:#000;
float:left;
width:120px;
height:25px;
}
It can be as per requirement
ul > li:hover li a { }
this is what I have
http://jsfiddle.net/ftKw5/
/* CSS element classes */
#font-face {
font-family:'myriad-webfont';
src: url('webfont/myriad-webfont.ttf') format('truetype'), url('webfont/myriad-webfont.svg#myriad_webfont') format('svg');
font-weight: normal;
font-style: normal;
}
body {
font-family: myriad-webfont;
color: #000000;
background: url('img/silk_pat#2x.png');
letter-spacing: 2px;
}
h2 {
;
font-size: 3;
}
::-webkit-input-placeholder {
color:#222222;
opacity:0.1;
}
/* CSS element IDs */
#outer-wrapper {
width: 50em;
margin: 1em auto;
background-position:inherit;
border: 2px solid #dcdcdc;
border-radius: 1.5em;
position:relative;
background-color: #ffffff;
}
#surtitle {
border-bottom: 1px solid #dcdcdc;
text-align: center;
opacity: 0.3;
font-size:15px;
letter-spacing: 7px;
}
#topnavbar {
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
opacity: 0.5
}
/* Dropdown */
.nav {
padding-top:-10;
height:36px;
background:#aaa;
color:#fff;
text-shadow:1px 1px #888;
z-index:400
}
.menu a {
float:right;
color:#eee;
text-decoration:none;
width:120px;
height:28px;
padding-top:8px
}
.menu span {
float:right;
color:#eee;
text-decoration:none;
width:120px;
height:28px;
padding-top:8px
}
.menu a:hover {
color:#fff
}
.menu {
list-style:none;
font:10px;
text-align:center;
width:600px;
margin:0;
}
.menu li {
position:relative;
float: right;
width:120px;
z-index:400
}
.menu ul {
margin:0;
padding:0;
outline:0;
display:none;
position:absolute;
font:10px;
top:36px;
left:0;
background:#aaa;
display:none;
list-style:none
}
.menu ul li {
float:none;
border-top:1px solid #ccc;
width:120px
}
.menu ul li a, li.menuhover li a, li.menuhover li.menuhover li a {
float:none;
display:block;
background:none;
height:22px;
padding-top:5px
}
.menu ul li a:hover, li.menuhover li a:hover, li.menuhover li.menuhover li a:hover {
background:#999;
color:#fff
}
.menu ul li span, li.menuhover li span, li.menuhover li.menuhover li span {
float:none;
display:block;
background:none;
height:22px;
padding-top:5px
}
.menu ul ul {
left:120px;
top:0
}
.menu li.submenu {
}
.menu li.noborder {
border-top:none
}
li.menuhover a, li.menuhover li.menuhover a {
color:#fff;
background:#999
}
li.menuhover span, li.menuhover li.menuhover span {
color:#fff;
background:#999
}
For some reason, when I run it, it won't hug the top etc. I added the jsfiddle so that it's a little better to read and you can see the html to go with it.
If i am understanding your questio0n correct the below css will help you.
CSS:
body {
font-family: myriad-webfont;
color: #000000;
background: url('img/silk_pat#2x.png');
letter-spacing: 2px;
padding:0; // it will remove padding from body tag
margin:0; // it will remove margin from body tag
}
Answer of new requirement in comments (Menu shoul be center of top bar ):
.menu {
list-style: none outside none;
margin: 0 auto;
overflow: hidden;
padding: 0;
text-align: center;
width: 368px;
}
.menu li {
float: left;
width: 120px;
z-index: 400;
}