CSS dropdown closes too early - html

My dropdown works fine, except it closes before i can move mouse top of last link in it.
CSS
nav {
width: 100%;
display: inline-block;
margin-bottom: 1%;
text-align: center;
background-color: #F0F0F0;
}
nav .links {
width: 100%;
line-height: 1.2;
font-size: 100%;
text-decoration: underline;
text-align: center;
}
nav .links a {
color: #666666;
text-decoration: none;
word-spacing: normal;
}
nav .links a:visited {
color: #666666;
text-decoration: none;
}
nav .links a:hover {
color: #383838;
text-decoration: none;
}
nav .links a:active {
color: #666666;
text-decoration: none;
}
nav ul {
position:relative;
list-style:none;
color: #666666;
white-space: nowrap;
}
nav li{
position:relative;
float: left;
margin-left: 5%;
}
nav ul li ul {
display: none;
position: absolute;
background-color: #F0F0F0;
border: 2px solid;
border-radius: 5px;
padding: 0.5em 1em 0.5em 0.5em;
line-height: 1.2;
}
ul li:hover ul {
display: block;
}
HTML
<nav>
<div class="links">
<ul>
<li>ETUSIVU</li>
<li>HENKILÖKUVA JA HISTORIA</li>
<li>KORISTEKERAMIIKKA</li>
<li>GALLERIA
<ul>
<li>Keramiikkaveistokset</li>
<li>Keramiikka - kuparityöt</li>
<!--Next link is the one where dropdown closes before mouse reaches it-->
<li>Krisu testi</li>
</ul>
</li>
</ul>
</div>
I tested it with Chrome and FF. CSS is not top skill for me and i think this should work but obviously im wrong :)
I would appreciate help with this greatly, thanks.
EDIT
I changed nav ul li ul as...
nav ul li ul {
z-index: 1;
display: none;
position: absolute;
background-color: #F0F0F0;
border: 2px solid;
border-radius: 5px;
padding: 0.5em 1em 0.5em 0.5em;
}
and now it works just fine. So basically i just added z-index there.
There is an image right below dropdows, not sure is it possible that it messes this one? Atleast z-index did help...

Related

Items in nav shift apart slightly when clicked

I have a nav element with 4 items.
When I click on any of the elements, I notice that the items shift apart slightly, and the div expands.
<div id="siteNavigation" class="navDiv">
<nav>
<ul>
<li><span>Home</span></li>
<li>Meet Me</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
.navDiv {
display: inline;
width: auto;
float: right;
border: solid;
}
nav ul {
clear: both;
list-style-position: inside;
clear: left;
list-style: none;
margin-left: 0;
width: auto;
padding-top: 32px;
text-align: center;
white-space: nowrap;
}
nav ul li {
display: inline-block;
white-space: nowrap;
padding-left: 8px;
border: none;
}
nav ul li a {
color: #000000;
/* #E3CF9C */
font-size: 1em;
font-weight: bold;
text-decoration: none;
letter-spacing: 0.05em;
padding: 10px 3.125% 26px 3.125%;
text-transform: uppercase;
border: none;
}
nav ul li a:hover {
color: #BF0000;
}
nav ul li a.selected {
color: #BF0000;
}
nav ul li a.selected:hover {
color: #E3CF9C;
}
JSFiddle example: https://jsfiddle.net/rfhasw48/1/
What do I need to change to make the nav stay a constant size?
Just remove the padding from nav ul li a.
Updated CSS:
.navDiv {
display: inline;
width: auto;
float: right;
border: solid;
}
nav ul {
clear: both;
list-style-position: inside;
clear: left;
list-style: none;
margin-left: 0;
width: auto;
padding-top: 32px;
text-align: center;
white-space: nowrap;
}
nav ul li {
display: inline-block;
white-space: nowrap;
padding-left: 8px;
border: none;
}
nav ul li a {
color: #000000;
/* #E3CF9C */
font-size: 1em;
font-weight: bold;
text-decoration: none;
letter-spacing: 0.05em;
text-transform: uppercase;
border: none;
}
nav ul li a:hover {
color: #BF0000;
}
nav ul li a.selected {
color: #BF0000;
}
nav ul li a.selected:hover {
color: #E3CF9C;
}

Hover not working in css

I'm here to ask a question I know is simple, but I just can not get it to work. I want to change the background color of my li tag to a different color once a user hovers over it.
HTML:
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
CSS:
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
}
nav ul li a {
color: #aaa;
background-color: #333;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
nav ul li:hover {
background-color: #666;
color: #000;
}
Any help will be greatly appreciated, thanks!
add an a to the hover and it works
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
}
nav ul li a {
color: #aaa;
background-color: #333;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
nav ul li a:hover {
background-color: #666;
color: #000;
}
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
The reason it doesn't work is that there are links inside the li tags - <a> tags. Those take on their own color when hovering. So you'll have to define your desired color for li a:hover { color: ...}
Your styling for the anchor tag is interfering with your li:hover instructions.
You have to think of them as layers, especially when you're using them as block elements. The dimensions of the anchor tag are bigger than the ones of the li tag, hence you don't see the hover effect. I corrected your code. This works:
nav {
background-color: #333;
margin: 0;
overflow: hidden;
width: 100%;
text-align: right;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
list-style-type: none;
background-color: #333;
}
nav ul li:hover {
background-color: #666;
color: #000;
}
nav ul li a {
color: #aaa;
background: transparent;
display: block;
line-height: 2em;
padding: 0.5em 0.5em;
text-decoration: none;
}
Try to see, if you notice what I changed. This helps you to understand what was wrong in the first place. :)

Can't centre navigation bar?

I've looked at so many questions of people asking how to centre a navigation bar, and I've tried lots of things and just cannot get it to move...
HTML:
<div id="header">
<h1>Midlands Car Club</h1>
<ul id="nav">
<li>Home</li>
<li>Members</li>
<li>Cars</li>
</ul>
</div>
CSS:
//header
#header {
width: 100%;
height: 150px;
}
#header h1{
font-family: "Vernada", sans-serif;
font-size: 1.8em;
text-align: center;
}
//navigation
#nav ul {
list-style-type: none;
padding: 0;
text-align: center;
}
#nav a {
display: inline-block;
width: 80px;
background-color: #dddddd;
text-align: center;
}
#nav li {
display: inline;
color: black;
font-family: "Vernada", sans-serif;
font-size: 1.2em;
}
#nav a:link {
width: 120px;
padding: 10px;
display: inline-block;
text-decoration: none;
color: black;
}
#nav a:visited {
display: inline-block;
text-decoration: none;
color: black;
}
#nav a:hover {
text-decoration: none;
color: grey;
}
#nav a:active {
text-decoration: none;
color: blue;
}
Most likely missed something out, or just gone about it wrong altogether. I've managed to get it working in the past but have completely forgotten how I did it...
#nav {
width : "however wide you want it";
margin: 0 auto;
}
It's the margin: 0 auto; that centers the element.
You could also use text-align on the parent element, but the margin trick is most commonly used.

Sub menu won't display

I have a hover drop down menu on my website. It displays ok until you hover over. The submenu appears but before you can click on a link, the sub menu vanishes.
Here is the HTML -
<div id="top-nav"><div id="nav">
<nav>
<ul id="menu" style="list-style-type: none;">
<li id="sub">Artists
<ul>
<li>Banks</li>
<li>Lil Silva</li>
<li>Frances and the Lights</li>
<li>Jim-E Stack</li>
</ul>
</li>
<li>Night</li>
<li>Info</li>
</ul>
</nav>
</div>
</div>
And here is the CSS -
#nav {
text-align:center;
list-style: none;
}
ul#menu {
background-color: #FFFFFF;
list-style: none outside none;
margin: 0 auto;
padding-bottom: 0px;
padding-top: 0px;
text-align: center;
width: 300px;
}
ul#menu:after {
content: "";
background-color: #FFFFFF;
height: 10px;
width: 100%;
display: block;
position: absolute;
left: 0;
margin-top: 20px;
}
ul#menu li {
float: left;
}
ul#menu li a {
color: #666666;
font-size: 12px;
margin: 0;
padding: 0px 35px;
text-decoration: none;
}
ul#menu li a:hover {
background-color: #ccc;
}
a.selected-page, ul#menu a.selected-page:hover {
background-color: #FFFFFF;
}
li#sub ul {
display: none;
position: absolute;
background-color: #FFFFFF;
z-index: 22222;
margin-top: 4px;
overflow: hidden;
}
li#sub ul li {
display: block;
float: none;
border-top-style: none;
border-width: 2px;
border-color: #FFFFFF;
text-align: left;
padding-top: 5px;
padding-bottom: 5px;
}
ul#menu li#sub:hover ul {
display: block;
}
ul#menu li#sub ul li:hover {
background-color: #FFFFFF;
}
What am I doing wrong? Any help is greatly appreciated!
the problem is the following line of your CSS code:
li#sub ul {
...
margin-top: 4px;
...
}
Just remove this margin-top and your drop down menu will work properly.
In your example there is a 4px margin space between the "Artists"-link and the drop down menu below. And if your cursors leaves the link and enters this "margin area", the browser interprets it as un-hovering the link - and hides the drop down.
Like dalucks said, remove the top margin from your CSS:
li#sub ul {
margin-top:0;
}
Also, reduce the left margin/paddings from the submenu UL and/or LI children. With the original large values (35px) the menu could be hovered over a lot of invisible space.
ul#menu li ul li a {
padding-left:5px;
}
Fiddle: http://jsfiddle.net/LXwTr/
Add Padding: 0 to this
li#sub ul {
padding: 0;
}
http://jsfiddle.net/tdQmE/

How do I fix ie 6 hover?

This is my code for my menu:
/*Menu*/
#menu {
text-align: right;
margin-left: auto;
margin-right: auto;
height: 50px;
position: relative;
z-index: 5;
font-size: 0.75em;
}
#menu ul {
margin: 0;
padding: 10px 5px 5px 5px;
list-style: none;
line-height: normal;
border: 0px solid #03426A;
-moz-border-radius: 6px;
background: #F3F4FF;
position:relative;
width: auto;
float:right;
}
#menu ul li {
float: left;
}
#menu li ul {
display: none;
}
#menu ul li a {
display: block;
text-decoration: none;
color: #000;
display: block;
padding: 0px 15px 5px 15px;
text-decoration: none;
text-align: center;
font-size: 1em;
font-weight: normal;
border: none;
}
#menu ul li a:hover {
color: #0A67A3;
}
#menu li:hover ul {
display: block;
position: absolute;
}
#menu li:hover li {
float: none;
font-size: 0.9em;
}
#menu li:hover a { color: #0A67A3; }
#menu li:hover li a:hover { color: #000; }
/*End Menu*/
I have tried 2 tutorials however have not found a way of making the menu work in ie 5.5 or 6. How can I fix this?
IE6 doesn't support :hover pseudoclass on elements other than anchor tags. Son of Suckerfish has a solution that may work for you: http://www.htmldog.com/articles/suckerfish/dropdowns/
IE 5.5? Really... Wow I feel sorry for you if you need to still be compatible that far...Legacy corporate app I suppose? Damn!!
IE6 only understands :hover for <a> elements that's for sure. But you can try the solution given here that uses a htc file to create a new css behavior: http://www.xs4all.nl/~peterned/csshover.html