Here is the html code of the page's navigation:
<nav>
<ul id="navigation">
<A class="scroll" href="#first">Hjem</A>
<A class="scroll" href="#second">Info</A>
<A class="scroll" href="#third">Pris</A>
<li style="display: inline;"><A class="scroll" href="#">Brugervejledninger »</A>
<ul>
<li>arbejdsleder</li>
<li>medarbejder</li>
</ul>
</li>
<a id="login-button" href="http://mintimeseddel.dk/scheduling/users">Log ind</a>
</ul>
</nav>
And following is the css used to style it:
ul#navigation li:hover > ul
{
visibility:visible;
opacity:1;
}
ul#navigation ul, ul#navigation ul li ul {
list-style: none;
margin: 0;
padding: 0;
visibility:hidden;
position: absolute;
z-index: 99999;
width:180px;
background:#f8f8f8;
box-shadow:1px 1px 3px #ccc;
opacity:0;
-webkit-transition:opacity 0.2s linear, visibility 0.2s linear;
-moz-transition:opacity 0.2s linear, visibility 0.2s linear;
-o-transition:opacity 0.2s linear, visibility 0.2s linear;
transition:opacity 0.2s linear, visibility 0.2s linear;
}
ul#navigation ul {
top: 43px;
left: 43%;
}
ul#navigation ul li ul {
top: 0;
left: 181px;
}
ul#navigation ul li {
clear:both;
width:100%;
border:0 none;
border-bottom:1px solid #c9c9c9;
}
ul#navigation ul li a {
background:none;
padding:7px 15px;
color:#616161;
text-shadow:1px 1px 0px #fff;
text-decoration:none;
display:inline-block;
border:0 none;
float:left;
clear:both;
width:150px;
}
Everything works as expected on the localhost, but the problem occurs once the site is uploaded to the live server, the navigation menu gets messed up. Even though it is browser specific: on firefox it always shows up properly, while the other browsers need to reload the page a few times to get it right.
A live example of it can be seen at: www.mintimeseddel.dk
Any help is much appreciated.
Your HTML is not valid. Browsers will interpret the invalid html differently in an effort to figure out what it is supposed to mean.
Namely, you can't put anchors ('a') directly inside of unordered lists ('ul'), the only valid child of a list is a list item ('li'). In other words, you need to wrap an 'li' tag around the 'a' tags.
Some browsers will close the list and display the anchors inside of the list's parent element (a 'nav' in this case). Other browsers will transparently wrap the anchors in a list entry. Others still will try to render the anchors where they are.
If you fix the HTML, the rest should start to work consistently (although you might have to go back and redo the CSS).
EDIT To respond to OP's comment: The HTML should look like this:
<nav>
<ul id="navigation">
<!-- note the new 'li' tags here -->
<li><a class="scroll" href="#first">Hjem</a></li>
<li><a class="scroll" href="#second">Info</a></li>
<li><a class="scroll" href="#third">Pris</a></li>
<li style="display: inline;"><A class="scroll" href="#">Brugervejledninger »</A>
<ul>
<li>arbejdsleder</li>
<li>medarbejder</li>
</ul>
</li>
</ul>
<!-- and another additional 'li' tag here -->
<li><a id="login-button" href="http://mintimeseddel.dk/scheduling/users">Log ind</a></li>
</nav>
Related
I made my website as responsive as possible(don't wanna know something about bootstrap). The only thing that doesn't stay in its place (which needs to stay in the middle). Here is my code:
#header {
position:fixed;
display:block;
width:100%;
top:0;
left:0;
padding-left:0vmax;
padding-right:5vmax;
z-index:99999;
height:8vmax;
max-height:8vmax;
transition: .3s linear;
box-sizing:border-box;
background-color: rgba(243,243,243,1.00);
}
#menuwrapper {
display:block;
float:right;
width:55vmax;
margin-top:0.35vmax;
margin-right:17vmax;
height:8vmax;
max-height:8vmax;
overflow:hidden;
box-sizing:border-box;
position:relative;
}
#menu {position:absolute;height:100%;width:100%;display:table;padding: 2.5vmax; word-wrap:break-word;}
#menu ul {word-spacing:2vmax;font-size:1.35vmax;padding:0;padding-bottom:0vmax;margin: 0 1vmax;}
#menu li {display:inline-block;padding: 0vmax;}
.rechts {display: table-cell;width: 1px;vertical-align: middle;white-space: nowrap;}
#menu ul li a {height:8vmax;text-decoration:none;color:grey;transition: color .45s ease-in-out;margin-right:7.5vmax;}
#menu ul li a:hover {color:#3f92c3;}
<div id="header">
<div id="menuwrapper">
<div id="menu">
<ul class="pad">
</ul>
<ul class="rechts">
<li><a class="a1" id="page1" href="javascript:;">Services</a></li>
<li><a class="a1" id="page2" href="javascript:;">Portfolio</a></li>
<li><a class="a1" id="page3" href="javascript:;">Contact</a></li>
</ul>
</div>
</div>
</div>
I made a jsfiddle but i can't see that it goes to much to the left like i saw on a tablet.
It is a tablet of work and it has long height. On my website it's better noticable My website If i change the height inside the desktop version. Then you see that the menu goes left and the first menu word disappears.
Is there a way to fix this?
You're overriding default properties without reason.
I tried to clean your css code a little bit, deleting what's not necessary.
I think now works as you expect, if not, specify a little bit more and i'll edit the code to help you understand how to do what you need.
#header {
position:fixed;
display:block;
width:100%;
top:0;
left:0;
padding-left:0vmax;
padding-right:5vmax;
z-index:99999;
height:8vmax;
max-height:8vmax;
transition: .3s linear;
box-sizing:border-box;
background-color: rgba(243,243,243,1.00);
}
#menuwrapper {
display:block;
float:right;
margin-top:0.35vmax;
margin-right:17vmax;
height:8vmax;
max-height:8vmax;
overflow:hidden;
box-sizing:border-box;
position:relative;
}
#menu {padding: 2.5vmax; word-wrap:break-word;}
#menu ul {word-spacing:2vmax;font-size:1.35vmax;padding:0;padding-bottom:0vmax;margin: 0 1vmax;}
#menu li {display:inline-block;padding: 0vmax;}
.rechts {vertical-align: middle; white-space: nowrap;}
#menu ul li a {height:8vmax;text-decoration:none;color:grey;transition: color .45s ease-in-out;margin-right:7.5vmax;}
#menu ul li a:hover {color:#3f92c3;}
<div id="header">
<div id="menuwrapper">
<div id="menu">
<ul class="pad">
</ul>
<ul class="rechts">
<li><a class="a1" id="page1" href="javascript:;">Services</a></li>
<li><a class="a1" id="page2" href="javascript:;">Portfolio</a></li>
<li><a class="a1" id="page3" href="javascript:;">Contact</a></li>
</ul>
</div>
</div>
</div>
When users hover my sub menu, the menu shows. I want the sub-nav to show only when the main nav is hovered.
For example, when "About" is hovered, it should display "Me, Us, and Them." But I should never be able to hover "Me, Us, or Them" WITHOUT hovering "About". Once the "About" is hovered, you should be able to hover "Me, Us, and Them" and they NOT fade away again.
li, ul {
list-style: none;
}
.navigation-bar {
width: 100%;
display: table;
}
.navigation-bar > ul {
display: table-cell;
cursor: default;
}
.navigation-bar > ul > li {
width: 10px;
cursor: pointer;
visibility:hidden;
opacity:0;
transition:visibility 0s linear 0.5s, opacity 0.5s linear;
}
.navigation-bar > ul:hover > li {
visibility:visible;
opacity:1;
transition-delay:0s;
}
<li class="navigation-bar">
<ul>About
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Find
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Shop
<li>Shirts</li>
<li>Pants</li>
<li>Hats</li>
</ul>
<ul>Contact
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
I'm not quite sure how to ask this. I hope you understand the question.
The sub menus should only show when the main (always shown) part is hovered.
No jQuery please.
I think I understood your question and will be my best to answer.
According to what I have seen it looks like you have a wrong hover area. The reason is that you are using the :hover on ul and your structure looks wrong.
First of all the .navigation-bar is just an li without any wrapping ul. This is an error, it should be ul, the menus should be li and then the dropdown menu should be ul and li
You are also using table-cell which is giving the li a lot of width that is why there is a wrong clickable area.
I have created the code for please have a look, I tried it on my computer and it is working fine
<ul class="navigation-bar">
<li>About
<ul>
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
<li>Find
<ul>
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
<li>Shop
<ul>
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
<li>Contact
<ul>
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
</ul>
li, ul {
list-style: none;
}
.navigation-bar {
width: 100%;
margin:0;
padding:0;
}
.navigation-bar:after{
clear:both;
content:'';
display:block;
}
.navigation-bar > li {
float:left;
position:relative;
margin-right:5%;
}
.navigation-bar > li > ul {
opacity:0;
transition:visibility 0s linear 0.5s, opacity 0.5s linear;
position:absolute;
top::0;
left:0;
margin:0;
padding:0;
visibility:hidden;
}
.navigation-bar > li:hover > ul {
opacity:1;
transition-delay:0s;
visibility:visible;
}
The rest of the changes you can do according to your requirement.
Again please note I answered this question according to what I understood, if I am wrong the please forgive me and explain again, so that I will try to answer better
It's all because you're using visibility: hidden. This won't have the same effect with display: none which will remove the element completely from the flow.
With visibility: hidden, the element will still be there but you just can't see it, so when it's hidden, the li will still be there with the auto height, this will cause it to trigger the :hover on ul if you hover on the hidden li because the li is the child of the ul, so if you hover over li, it means you also hover over ul and cause the problem that you get.
The way to solve this problem is either using display: none and display: block like answered by Sanjeev, but it won't have the fade effect.
If you want to still have the fade effect, you can set the max-height of the li to 0 when not hovered, and when hovered, set it to something far from your element height, like 1000px or more.
Here's the Fiddle on how to use the max-height which will preserve the fade effect
*Note: As noted by Zaqk, display: table-cell is not the proper way to achieve the UI, you can change it to display: inline-block like answered by Zaqk here.
li, ul {
list-style: none;
}
.navigation-bar {
width: 100%;
display: table;
}
.navigation-bar > ul {
display: table-cell;
cursor: default;
}
.navigation-bar > ul > li {
width: 10px;
cursor: pointer;
visibility:hidden;
opacity:0;
transition:visibility 0s linear 0.5s, opacity 0.5s linear, max-height 0.5s linear;
max-height: 0;
}
.navigation-bar > ul:hover > li {
visibility:visible;
opacity:1;
transition-delay:0s;
max-height: 100px;
}
<li class="navigation-bar">
<ul>About
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Find
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Shop
<li>Shirts</li>
<li>Pants</li>
<li>Hats</li>
</ul>
<ul>Contact
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
Well first off your HTML and CSS are a bit goofy.
But your actual issue is that visibility: hidden does not prevent your submenu from getting mouse events.
EDIT: Just noticed you have a fade effect. That makes things a little more complicated because you cannot transition to or from display: none. Kyojimaru has suggested a hack using the max-height property which is your best option if you care about old browsers.
The modern way to do this (shown below) is to just use the pointer-events property. Make sure you check support for pointer-events before you use it. If you need your site to work on IE10 and below, you’re better off using Kyojimaru’s hack.
HTML:
<nav>
<span>
About
<menu>
Me
Us
Them
</menu>
</span>
<span>
Find
<menu>
Me
Us
Them
</menu>
</span>
<span>
Shop
<menu>
Shirts
Pants
Hats
</menu>
</span>
<span>
Contact
<menu>
Me
Us
Them
</menu>
</span>
</nav>
CSS:
/* Layout
------------------------------------------- */
nav {
display: flex;
justify-content: space-around;
}
nav menu {
position: absolute;
z-index: 1; /* display menu above any page content */
}
nav menu a {
display: block;
}
/* Aesthetics
------------------------------------------- */
nav a {
text-decoration: none;
color: initial;
}
/* Interaction
------------------------------------------- */
nav menu {
opacity: 0;
transition: opacity 0.5s;
pointer-events: none;
}
nav span:hover menu {
opacity: 1;
pointer-events: all;
}
Demo: http://jsbin.com/seqoqi/9/edit?html,css,output
Let me know if you have any questions. :)
The problem in your code is you should not use visiblity:hidden in your .navigation-bar > ul > li.
Using that simply makes your list items (<li></li>)invisible.
You should use display:none and display:block
See the modified code snippet which is working as you are expecting.
li, ul {
list-style: none;
}
.navigation-bar {
width: 100%;
display: table;
}
.navigation-bar > ul {
display: table-cell;
cursor: default;
}
.navigation-bar > ul > li {
width: 10px;
cursor: pointer;
display:none;
opacity:0;
transition:visibility 0s linear 0.5s, opacity 0.5s linear;
}
.navigation-bar > ul:hover > li {
display:block;
opacity:1;
transition-delay:0s;
}
<li class="navigation-bar">
<ul>About
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Find
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
<ul>Shop
<li>Shirts</li>
<li>Pants</li>
<li>Hats</li>
</ul>
<ul>Contact
<li>Me</li>
<li>Us</li>
<li>Them</li>
</ul>
</li>
I have a bit of a problem, for the header of my website i used a styled div, called a so my http://puu.sh/d9Ax5/2817017ea2.png
but when i try to post a link i can't see it since it is already styled for the header.
Here is my code:
HTML HEADER LIST
a {
text-decoration: none;
color: #fff;
transition: all 0.2s ease-in;
}
CSS
<div class="nav">
<ul>
<li>Home</li>
<li>News</li>
<li>Content Packs</li>
<li>About</li>
<li>Help</li>
</ul>
</div>
Instead of giving style directly to a, use .nav a.
.nav a {
text-decoration: none;
color: #fff;
transition: all 0.2s ease-in;
}
This will help you to give the styles only to the 'a' inside the nav class and not any other 'a' in your code.
I've followed a few tutorials and fiddled with it to create a drop down menu come out from the website's logo.
This all works perfectly as I aimed for it to. To add effect I'd like to be able to have the menu items calmly fade in instead of just bam there.
I've tried to follow tutorials but I think I've butchered the CSS list enough that it's hard to put in place.
I need to logo to be the parent link which when hovered over drops down the options and not have it's shape, padding, boarders etc. effected by the li class so I created the sub class to prevent that.
Here's the HTML in question.
<nav>
<ul>
<li><div id="logo"><img src="images/logo.png" width="318" height="85" alt="Logo of Website"/></div>
<ul>
<li class="sub"> Much
</li>
<li class="sub"> Navigation
</li>
<li class="sub"> Very
</li>
<li class="sub"> Links
</li>
<li class="sub"> Wow
</li>
</ul>
</li>
</ul>
</nav>
And my mess of a Stylesheet
li {
list-style:none !important;
}
.sub {
padding:5px;
width:300px;
margin-bottom:1px;
border:rgba(0, 0, 0, 0.2);
height:20px;
vertical-align:central;
}
nav ul {
padding:0;
margin:0;
}
nav ul li {
list-style: none;
float:left;
background-color:rgba(0, 0, 0, 0.5);
}
nav ul li a {
text-decoration:none;
color:white;
font-family:'Merriweather', Baskerville, "Century Schoolbook L", "Times New Roman", serif;
font-weight:300;
color:white;
font-size:0.9em;
}
li a:hover {
font-style:italic;
word-spacing:3px;
height:20px;
}
nav ul li ul {
display:none;
}
nav ul li:hover ul {
z-index:5;
display:list-item !important;
position:absolute;
margin-top:90px;
}
nav ul li:hover ul li {
float:none;
}
And a JSFiddle link which shows you a box which is the logo and when you hover over it the menu appears below it... I'm aiming to get that menu list to fade into existence and not just jump out behind the logo.
JSFiddle
Try CSS3 transitions if you don't want to use jQuery. I think your markup may need some rewriting, but try for example:
transition:All 1s linear;
-webkit-transition:All 1s linear;
-moz-transition:All 1s linear;
-o-transition:All 1s linear;
In my HTML5 code I am using lists to create tabs in my navigation bar.
<div id="nav_tabs">
<ul>
<a href="Index_V2.html">
<li>
Home
</li>
</a>
<a href="#media">
<li>
Media
</li>
</a>
<a href="#agenda">
<li>
Agenda
</li>
</a>
</ul>
</div>
When the user hovers over one of those tabs the background color and text color changes. However, for my Media tab in my list I added a drop-down menu. The HTML for that is:
<a href="#media">
<li>
Media
<ul class="submenu">
<li>Music</li>
<li>Photo</li>
<li>Video</li>
<li>Band</li>
<li>Interviews</li>
<li>Archive</li>
</ul>
</li>
The drop down menu works and the Media tab background color changes to white on hover as it is supposed to. Unfortunately, the "Media" text in the tab remains its original color.
This is the CSS that handles the change of color etc:
nav {
width: auto;
text-transform: uppercase;
background: #ff4e00;
height: 50px;
}
nav a {
color: white;
}
nav ul {
list-style-type: none;
margin: 0 auto;
margin-left: 0px;
}
nav ul li {
height: 35px;
margin: 0px;
padding-top: 15px;
padding-left: 15px;
padding-right: 15px;
float: left;
text-align: center;
color: white;
font-size: 26px;
-webkit-transition: .2s linear;
-moz-transition: .2s linear;
-o-transition: .2s linear;
-webkit-transition: .2s linear;
-moz-transition: .2s linear;
-o-transition: .2s linear;
}
#nav_tabs ul li:hover {
background: white;
color: #ff4e00;
}
.submenu {
position: relative;
width: 10px;
top: 17px;
right: 15px;
padding: 0px;
margin: 0px;
display: none;
background: black;
}
.submenu li {
background: #ff4e00;
width: 150px;
}
li:hover .submenu {
display: block;
}
I am trying to get the "Media" link text to change to the same color as all the others, but since the Link/List order is different it obviously doesn't work the same. I have tried to use:
#nav_tabs ul a:hover {
color: #ff4e00;
}
But this only changes the color of the text when the user hovers over the link/text. It does not change the color of the text when the user hovers over the tab which is what I am looking for.
I managed to recreate my issue here in JS Bin. When the user hovers over the "Media" tab, the background of the tab changes but the text-color does not.
The short answer is this:
Instead of:
#nav_tabs ul a:hover {
color: #ff4e00;
}
Do this:
#nav_tabs ul:hover a {
color: #ff4e00;
}
You can place the :hover on any element in the CSS selector chain, it doesn't have to go on the last one. This means that when you hover over a UL, all of the child anchor tags will get the styles.
But a longer answer is you have poorly formatted HTML. You have empty anchor tags floating in the <ul> tags by themselves, instead of wrapped in <li> elements. You've also got anchor tags wrapping <li> elements rather than inside of them.
This means your whole cascading relationship is going to be off. Here is the revised HTML (I removed some stuff for simplicity, I'll let you add it back in using this new structure as a guide):
<body>
<nav id="nav_tabs">
<ul>
<li>Home</li>
<li>
Media
<ul class="submenu">
<li>Music</li>
</ul>
</li>
</ul>
</nav>
</body>
And then you should be able to adjust the CSS accordingly.
As some one mentioned in the comments, your HTML is not valid,
valid chields of are only s (you have to put the inside them).
In your code when the browser parse it .. tags get replaced and your css dont match it.
Here is the edited code: http://jsbin.com/ofapac/8/edit
<nav>
<div id="nav_tabs">
<ul>
<li>
Home
</li>
<li>
Media
<ul class="submenu">
<li>Music</li>
<li>Photo</li>
<li>Video</li>
<li>Band</li>
<li>Interviews</li>
<li>Archive</li>
</ul>
</li>
<li>
<a>Agenda</a>
</li>
<li>
<a>Contact</a>
</li>
</ul>
</div>
</nav>
And second thing, tags does not inherit font settings from there parent tag, so you have to specified it explisidly. there are 2 extra rows on the bottom of the CSS.
nav ul li a{
color: white;
}
nav ul li:hover > a{
color: #ff4e00;
}