CSS menu items not showing in chrome - css

For some reason, this works in firefox and iexplore but not chrome.
It is supposed to hide the submenu until the mouse rolls over it - in chrome the mouseover clearly works as the colour changes etc, but the menu does not pop out!
any help you can offer would be amazing!
thanks!!
#menu, #menu ul
{
margin:0px;
padding:0px;
list-style:none;
list-style-position:outside;
position:relative;
line-height:2em; /* this would mean the element is double the height of the font */
}
/* set up colours, borders and element padding */
#menu a:link, #menu a:active, #menu a:visited
{
display:block;
padding:0px 5px; /* shorthand padding - this means top and bottom padding is 0, left and right are 5px */
color: #000000; /* link text colour */
text-decoration:none;
background-color:#F90; /* specifies background colour of links */
font-weight:bold;
color:#FFC;
/* border stuff */
border:1px solid #F90; /* shorthand, border is 1px wide, solid and coloured */
}
/* set up hover colour for links */
#menu a:hover
{
background-color:#FC6;
color:#900;
border:1px solid #F60;
}
/* position menu elements horizontally */
#menu li
{
width:7em;
position:relative;
}
/* position and hide nested lists (width required to make menu display vertically) and "top" value needs same measurement as defined for #menu */
#menu ul
{
position:absolute;
width:7em;
left:7em; /* same value as width - no bigger otherwise gap will appear and menu will not work */
top:0em; /* line up with parent list item */
display:none;
}
/* set width of links to 12em */
#menu li ul a
{
width:7em;
float:left;
}
/* display information for sub-menus */
#menu ul ul
{
top:auto;
}
#menu li ul ul
{
left:7em;
margin: 0px 0px 0px 10px; /*shorthand margin command */
}
/* display when rolled over - also number of sub-menus to display - if wanted to use more submenus, would need more UL's (ie ul ul ul instead of ul) */
#menu li:hover ul ul
{
display:none;
}
#menu li:hover ul, #menu li li:hover ul
{
display:block;
}

I came across this searching for a solution to a similar problem. OP's site seems to work in Chrome now, but I found that the problem was in the way Chrome handles certain elements. There was a 1px gap between the main menu item and the submenu item, and hitting that gap with the cursor would hide the submenu. The solution was to set margin-top on the submenu to -1px to remove that gap. In OP's case, it appears that gap would have been to the left of the submenu rather than the top.
Note: Mine differs from OP in that I have used <div> rather than <ul> and <li>, but the principle's the same.
site: WeirdCalculator.com
From CSS stylesheet:
.menuitem {
display: inline;
}
.menuitem:hover .show {
margin-top: -1px;
}

#lipelip is almost right.
You have to remove position: relative from just the inner <li> tags - not the outer ones.
If that's difficult to understand, you could just add this to your CSS instead:
#menu li ul li
{
position:static;
}
It fixes the problem by setting the correct position property on the inner <li> tags only.

Remove the position:relative; you have on the #menu li {}
Not sure why it's not working in Chrome but I don't think you need it anyway.

Also please check float property for this issue. There is a float:none in my CSS, I removed the float and it resolved my issue of text whch was not appearing on popup menus in Chrome.

Related

Keeping dropdown menu active (visible) even after hover out

My sub menu disappears immediately after I move my mouse pointer to scroll towards the sub menu. Feel like I have screwed my CSS somewhere. I could not figure out after several attempts to make it stay active. I followed few tutorials(have a look at it) where they have called the hover on the ul instead of a(anchor), I tried similar ways but could not achieve what I want. Please point out where I have made the mistake. Here is my fiddle(my code). Sample CSS code for hover is below.
#topnav ul li ul
{
display: none;
position: absolute;
text-align: left;
background:#510000;
top:30px;
}
#topnav ul li:hover ul
{
display: block;
}
Put the padding on your list items instead of your ul or container. That way the dropdown overlaps your hover element and your browser never thinks that you hovered out of the element. See this:
#topnav li {
display:inline-block;
padding:10px 0;
margin-right:30px;
position: relative;
}
http://jsfiddle.net/jeffreyTang/q5cmqLrf/1/
You can also give
#topnav ul li ul {
padding-top:30px
}
instead of:
#topnav ul li ul {
top:30px
}
The problem is with your padding being at the nav level and you trying to make the drop down appear below it. Because you position your dropdown away from the parent li, you're no longer hovering over it when you move your mouse down. To fix, remove the padding from the nav and add it to the li.
remove padding from here:
#topnav{
display:block;
clear:both;
width:500px;
margin:0;
padding:0;
text-align:center;
}
add to here:
#topnav li{
display:inline-block;
padding: 15px 0 15px 5px;
margin-right:30px;
position: relative;
}
remove top from here:
#topnav ul li ul {
display: none;
position: absolute;
text-align: left;
background:#510000;
}
fiddle: http://jsfiddle.net/zj8krh95/7/
Here's a way to do it (it's more of a trick):
http://jsfiddle.net/zj8krh95/5/
#topnav ul li:hover {
padding-bottom: 10px;
margin-bottom: -10px; /* so that the menubar's height stays the same */
}
#topnav ul li:hover ul {
margin-top: -10px; /* so that the menu opens at the right position */
}
Basically, on hover, i extend the menu item's height so that no mouseout is trigger when i move down to the menu.

Hover query - NAV bar CSS effecting DIV class

The following CSS code creates a NAV bar with some sample boxes within a container.
I was having problems with the Hover staying on so with some advice from here I included the extra code (second block of code down)
.dropdown>ul>li>a:hover {margin-bottom:20px;}
This extra code worked well
However it has had a side effect on my DIV boxleft in that in wont stay left - as I move the mouse across the NAV bar it moves with it......... I just want to keep DIV boxleft on the left hand side. Can you help? Many thanks.
/* Navigation Style */
.dropdown { position:relative; font-family: arial, sans-serif; width:100%; height:40px; border:1px solid #666666; font-size:14px; color:#ffffff; background:#333333; z-index:2; }
/* Basic List Styling (First/Base Level) */
.dropdown ul {padding:0; margin:0; list-style: none;}
.dropdown ul li {float:left; position:relative;}
.dropdown ul li a { border-right:1px solid #666666; padding:12px 8px 12px 8px; display:block; text-decoration:none; color:#000; text-align:center; color:#fff;}
.dropdown>ul>li>a:hover {margin-bottom:20px;}
.dropdown ul li a:hover {color:#ffffff; background:#232323;}
/* Second Level Drop Down Menu */
.dropdown ul li ul {display: none;}
.dropdown ul li:hover ul { font-size:13px; display:block; position:absolute; top:41px; min-width:150px; left:0;}
.dropdown ul li:hover ul li a {display:block; background:#000; color:#ffffff; width:170px; }
.dropdown ul li:hover ul li a:hover {background:#666666; color:#ffffff;}
/* Third Level Drop Down Menu */
.dropdown ul li:hover ul li ul {display: none;}
.dropdown ul li:hover ul li:hover ul { display:block; position:absolute; left:145px; top:0; }
#container {
overflow:hidden;
background-color:yellow;
width:1250px;
padding 10px 10px 10px 10px;
border:1px solid #666666;
margin: 0 auto;
}
.boxleft {
float:left;
background-color:blue;
margin-top:30px;
margin-bottom:10px;
margin-left:10px;
margin-right:10px;
width:600px;
border:1px solid #666666;
z-index:1;
}
EDIT
Fiddle here : - http://jsfiddle.net/LUzNm/
Rather than address this band-aid fix, let's address the root problem!
To begin, you don't need that margin-bottom: 20px thing. That was never the cause of your initial problem. Rather, it was due to the fact that your .dropdown bar is 40px in height, but your actual dropdowns are absolutely positioned at 41px from the top. If the browser registers a mouse event while the mouse is over that 1px gap, the dropdown will close.
Now, it seems like you want that 41px so a border: 1px solid #666666 on your .dropdown bar will appear. We can do that still, but we'll just be adding that border to your hover menu.
And finally, let's get some best practices going. Padding can be useful, but padding for this use case sucks. Its far easier and more accurate to instead use line-height to achieve the height and spacing in our <a> tags rather than padding, and it allows us to do away with the extra padding-top and padding-bottom declarations on your site title! By setting line-height to 40px, we immediately match the height of the .dropdown bar at all times (and if you're using something like LESS or SASS, it becomes a great variable to reuse).
With all that being said, here's the updated fiddle: http://jsfiddle.net/2r5Mz/
One more thing that I would also recommend doing is moving the entire .dropdown container out of #container. The reason for this is #container has overflow: hidden set, which can mean chopping off your dropdown if the content isn't of sufficient height. Simply moving this .dropdown out of that div solves the issue.

Menu moves when hovered over

I've created a rollover image menu in Dreamweaver. The days of the week are images. So is the rollover image that appears on hover. My problem is when you hover over the days of the week, the hover image pushes the text down.
I've mocked together two screen grabs showing the menu before and during it's hover (http://static.tumblr.com/2wdsnoc/FbPmx6mez/hover-example.png)
I read about z-indexes and tried making the menu have a greater number than the hover but that hasn't worked, nor did it help making the position fixed. In the end this is the only CSS I have styling the menu -
== CSS ==
#nav {
text-align:center;
list-style: none;
}
#nav ul
{
list-style-type:none;
}
#nav li
{
display:inline;
text-decoration:none;
}
Here is the JSfiddle with the full javascript, html and css I've shown just one category for ease.
Thank you in advance!!
Using Javacript is overkill for what you're trying to accomplish, just use a sprite image, and manage the rest via CSS
JSFiddle Demo
HTML:
<ul>
<li class="home">Home</li>
</ul>
CSS
ul { float:left}
ul li { float:left; list-style:none; }
ul a { display:block; text-indent:-9999em; }
ul li.home { width:100px; height:50px; }
ul li.home a { background:url(http://placehold.it/100x100) no-repeat 0 0 }
ul li.home a:hover { background-position:0 -50px; }
Try this http://jsfiddle.net/r2FF7/18/
#nav li a img{
vertical-align:bottom;
}
Full page on: http://jsfiddle.net/r2FF7/18/show/

CSS drop down menu on focus disappears when accessing with keyboard

I have a CSS drop down that appears on either mouse over or keyboard focus, and though the drop down is accessible with the mouse, when you try to access it with the keyboard the the drop down vanishes (but you still cycle through the items).
Anyone have some ideas on how to keep the drop down visible when accessing the drop down menu items with the keyboard? The CSS code is below.
You can access a demo at: http://testingtesting1.info/joomla-test/
the HTML code is generated by Joomla.
/* Parent menu items */
.h-nav {
width:720px;
height:90px;
}
.h-nav ul {
left:0;
}
.h-nav li {
display:block;
list-style:none;
position:relative;
float:left;
margin-right:10px;
}
.h-nav a {
display:block;
padding:33px 24px;
margin:0;
float:left;
}
.h-nav li a:hover,
.h-nav li a:focus {
background-color:#ffbb58;
}
.h-nav li.parent {
background:url("../../images/standard/arrow-down.png")no-repeat right;
}
/* Sub menu links */
.h-nav li li a {
text-align:left;
}
.h-nav li li a:hover,
.h-nav li li a:focus {
text-decoration:underline;
background-color:transparent; /* hide the background-color:#ffbb58 */
}
/* 1st Sub menu dropdown */
.h-nav li.parent ul.nav-child {
margin:4px auto;
position:absolute;
margin-left:-9999%; /* using margin-left instead of display:none; because display isn't read by screen readers */
text-align:left;
padding:10px 5px;
width:220px;
background:url("../../images/standard/bg-submenu.png") repeat;
z-index:9999;
/*rounded corners - rounding only bottom corners */
border-bottom-right-radius:10px 10px;
border-bottom-left-radius:10px 10px;
-moz-border-bottom-right-radius:10px 10px;
-webkit-border-bottom-left-radius:10px 10px;
}
/* keeps the drop down visible when hovering over parent menu */
.h-nav li.parent:hover .nav-child,
.h-nav li.parent a:focus + ul.nav-child {
margin:auto;
top:90px;
}
/* Resize the padding for the drop down menu items */
.h-nav li li a {
display:block;
padding:2px 25px;
}
If you don't have the ability to access the html and manually add a tabindex, or it is dynamically generated every time, you can use Javascript to add a tabindex to the li elements (this is with jQuery):
$(document).ready(function(){
$('.h-nav>li').attr('tabindex',0);
});
or regular Javascript:
window.onload=function(){
menu = document.getElementById("h-nav")
navElems = menu.getElementsByTagName('li');
for(e = 0; e < navElems.length; e++){
if(navElems[e].parentNode == menu){
navElems[e].tabIndex = 0;
}
}
}
If you can't add a tabindex, I don't believe there is any other way to focus on the li
EDIT 9/21/13
This is not perfect, but it would be usable for keyboard only.
JS Fiddle
For it to work, you can't have a sub-ul that contains the li's with anchors; the anchors must be siblings. This solution uses the ~ selector, which unfortunately only applies to siblings after the targeted element, so it makes the anchors before the focused one disapear.

Works fine with firefox but have some issue with google chrome and browser resizing?

I have created the menu. This works quite fine in firefox but in google chrome, the hover is not displayed. Also when I resize my browser part of the menu hides and is not scrollable, I tried with MENU width:100%;, but when I do this and resize the browser, the class layout is distorted and displays out of the line of menu, the menu is distorted. Is there anyway to solve this problem:
so i forcefully define the width of the menu to 1366px to avoid menu distortion. Please help.
#mainmenu {
width:1366px;
height:50px;
/*position:relative;*/
position:fixed;
top:18px;
padding-left:200px;
line-height:50px;
background:#0b2c3d;
z-index:10;
box-shadow:5px 0px 15px #7e7a7a;
}
#mainmenu, #dd_home, #dd_profile, #dd_achv, #dd_contact,#dd_login {
cursor:pointer;
}
#mainmenu ul {
list-style-type:none;
margin:0px;
padding:0px;
}
#mainmenu ul li {
text-decoration:none;
float:left;
/*border-right-style:dotted;*/
}
#mainmenu ul li a {
text-decoration:none;
display:block;
width:150px;
text-align:center;
text-transform:uppercase;
color:white;
}
#mainmenu ul li.home {
width:150px;
text-align:center;
margin-top:-5px;
border-bottom:5px solid #0a68fb;
}
#mainmenu ul li.home:hover {
display:block;
background-color:#0a68fb;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
#mainmenu ul li.profile {
margin-top:-5px;
border-bottom:5px solid #ed4901;
}
#mainmenu ul li.profile:hover {
display:block;
background-color:#ed4901;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
#mainmenu ul li.achv {
margin-top:-5px;
border-bottom:5px solid #27fb06;
}
#mainmenu ul li.achv:hover {
display:block;
background-color: #27fb06;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
#mainmenu ul li.contact {
margin-top:-5px;
border-bottom:5px solid #b70bfb;
}
#mainmenu ul li.contact:hover {
display:block;
background-color:#b70bfb;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
#mainmenu ul li.contact:checked {
margin-top:-5px;
border-bottom:10px solid #b70bfb;
}
#mainmenu ul li.login {
margin-top:-5px;
border-bottom:5px solid #36b096;
}
#mainmenu ul li.login:hover {
display:block;
background-color:#36b096;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
#mainmenu ul li.nepal {
margin-top:-5px;
border-bottom:5px solid #f8d605;
overflow:hidden;
}
HTML
<div id="mainmenu">
<ul>
<li class="home"> Home
<li class="profile"><a href="profile.aspx" >Profile</a>
<li class="achv">achievements
<li class="contact">Contact
<li class="login">Log in
<li class="nepal">jaya nepal</li>
</ul>
</div>
JSFiddle: jsfiddle.net/gzeLS
Remove the display:block from your :hover styles:
jsfiddle.net/gzeLS/1
Or, add display:block to the non-hover styles:
jsfiddle.net/gzeLS/2
I'm not sure why Chrome doesn't like that. I'd say it's a Chrome bug.
To get the menu to resize, do some work with max-width and min-width. You'll only be able to get it about 600px wide before text starts overlapping. Prevent overlapping by giving the menu a min-width.
jsfiddle.net/gzeLS/3
But then, as you've already discovered, part of the menu is hidden when the window is too small. Even if you set a min-width on the body to get scroll bars to appear, you still won't be able to scroll the menu because you are using position: fixed. Your best bet would be to use media queries to shrink the font size if the window is below a certain width.
jsfiddle.net/gzeLS/4
Edit: Here's a breakdown of the changes I made to get to the third jsFiddle where centering works regardless of window size.
To get the menu to fill the page, rather than specify width, specify left and right.
To position the menu items in the center:
Use text-align: center on the menu, not padding. This will account for different window sizes.
Set display: inline-block on the ul to make it centerable.
Set width and max-width on the ul. Using width allows us to size the li elements by percent, which lets them shrink if the window is too small. And max-width let's us actually center the menu items, giving the margin on the right and left when the window is wide enough to fit the menu at full width.
To prevent the menu items from wrapping when the screen is too small, set white-space: nowrap on the ul.
To prevent the text of the menu items from overlapping when the window is too small to fit the entire menu:
Set min-width on the menu.
Set overflow: hidden on the menu items.
For simplicity, I also consolidate redundant styles from the list items by class into the li selector.
Here are the changes I made in the fourth jsFiddle to get the menu to fit a smaller window and remain visible:
Remove min-width from the menu to allow it to shrink to fit the window.
Add media query styles to progressively decrease the font size as the window size decreases:
#media all and (max-width: 640px) { #mainmenu { font-size: 90%; } }
#media all and (max-width: 590px) { #mainmenu { font-size: 80%; } }
#media all and (max-width: 530px) { #mainmenu { font-size: 70%; } }
#media all and (max-width: 468px) { #mainmenu { font-size: 60%; } }
If you make this small change, for example on the home link:
#mainmenu ul li.home:hover
TO
#mainmenu ul li.home a:hover
Then you'll notice that your hover properties are properly displayed in Chrome and Firefox.
JSFiddle for this fix
UPDATE
And here's a fix for your second problem.
You need to set the text-align of your master div to center in order to center a ul within a container. The typical margin: 0 auto; won't work. I added a white-space:nowrap; as well to prevent breaking when the screen is smaller than the horizontally aligned menu items.
Hope this helps.

Resources