submenu pure css and html disappears - html

I have a menu which has a submenu. the submenu appears when i hover the main menu, but as soon as i try to go down to the submenu it disappears most of the time. Only if i'm very fast I'm able to get to it before it disappears.
HTML:
<header>
<div class="wrapper">
<img src="images/logo.png" width="125" height="20" alt="">
<nav class="fl">
<ul >
<li> Target Groups
<ul>
<li>Manage Target Groups</li>
<li>Create Target Group</li>
</ul>
</li>
<li>Activity</li>
<li>Reports</li>
<li>Settings</li>
<li>Admin</li>
</ul>
</nav>
</div>
<!-- end .wrapper -->
</header>
CSS:
header{
margin-top: 30px;
background: url(../images/header-bg.png) no-repeat;
width: 942px;
height: 76px;
padding: 27px 25px 5px;
}
header .wrapper{
border-bottom: 1px solid #e5e5e5;
float:left;
width: 862px;
padding: 0 40px 5px;
position:relative;
}
header nav{
margin-left: 45px;
}
header nav ul{
z-index: 100;
}
header nav ul li{
display: inline;
margin-right: 35px;
line-height: 20px;
z-index: 100;
}
header nav ul li ul{
display: none;
position:absolute;
width: 962px;
left: 0;
top: 40px;
}
header nav ul li ul li{
float: left;
}
header nav ul li:hover ul{
display:block;
}
header nav ul li a{
font-size:16px;
color: #5b666a;
text-decoration: none;
padding: 5px 10px;
}
header nav ul li a.selected,header nav ul li a:hover{
background: #657073;
color: white;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
I'm really stuck, please help...

In order to achieve what you want, it's better to use padding-top for your submenu, instead of absolute positioning (with the latter you'll end up with 'empty' space between menu and submenu, causing mouseout):
http://jsfiddle.net/BAzx7/
EDIT: And I added position:relative; to ul li, and a lower z-index to ul li ul, otherwise the submenu would be over the main menu - and disable it...
http://jsfiddle.net/BAzx7/1/

I've also fixed this with hoverIntent on one of my drop downs. Was an exclusive IE bug at the time but was a easy fix.
http://cherne.net/brian/resources/jquery.hoverIntent.html
This is how my function looked.
$('.main-nav > ul > li').hoverIntent({
timeout: 300,
over: function () {
$(this).addClass('hover')
},
timeout: 300,
out: function () {
$(this).removeClass('hover')
}
});
My markup was in the same structure as the son of sucker fish menu.

Related

Navigation Menu Causing Entire Nav Layer to Dissappear Html / CSS

So I'm, attempting to create a drop down menu on my website and for the most part have been successful, however I'm having one issue.
<div id="nav">
<ul>
<li>content</li>
<li>
content
<ul>
<li>subcontent</li>
<li>subcontent</li>
<li>subcontent</li>
</ul>
</li>
<li>content</li>
<li>content</li>
</ul>
</div>
Above is the content
body{
margin: 0px;
}
ul, li{
margin: 0px;
padding: 0px;
}
#nav{
width: 100%;
background-color: #000000;
color: #ff0000;
}
#nav ul{
position: absolute;
list-style-type: none;
text-align: center;
cursor: pointer;
}
#nav ul li{
min-width: 100px;
display: inline-block;
border: 1px solid #000000;
}
#nav ul li:hover{
background-color: #0000ff;
}
#nav ul li ul li{
display: none;
margin-left: -1px;
margin-top: -1px;
}
#nav ul li:hover ul li{
display: block;
}
And that is the CSS
Basically, because I'm positioning my content as 'absolute' in order to stop anything from being misplaced when the dropout menu is used, the layer black layer which acts as the navigation bar section ends up disappearing. Is there any way around this, or do I need to restructure my website completely?
This is what is looks like in a browser:
Try adding background-color to ul, li
ul, li{
margin: 0px;
padding: 0px;
background-color: #000;
}
or give #nav a height
#nav{
width: 100%;
background-color: #000000;
color: #ff0000;
height: 50px;
}
Never mind, I realized it was because I hadn't set a height in #nav.

CSS Dropdown pushes content down page

This is a simple dropdown menu. It's a free template that uses webkit (only learning about what this is). I'm not very good with CSS and I can change so that the dropdown menu will not push the other content down the page, but this creates other problems.
The other problems being that the background of the dropdown menu is no longer red, but transparent and the transition doesn't work.
Additionally, even with a transparent background, when I hover over the dropdown menu, I cannot hover over the entire list without the menu collapsing. For example, in the list below, there are 4 items, Basic, Basic Plus, Ultra, and Ultra Plus. When I've set the ul to position:relative the menu no longer pushes the rest of the content down the page, but when I try to hover over Ultra, the menu goes away.
Here is where I'm developing it:
http://www.oklahomastepparentadoption.com/truck-web/index.php
I really like how the transition works on the entire drop down menu (slide down from the top).
This is the CSS code (HTML below)
.top-nav{
float: right;
width: 70%;
}
.top-nav ul{
padding:0;
margin:0;
}
.top-nav ul li{
display: inline-block;
width: 18%;
margin-right: .4em;
float: left;
position: relative;
}
.top-nav ul li.active{
background: #bb1e10;
}
.top-nav ul li a{
color: #FFF;
font-size: 18px;
margin-right: .4em;
float: left;
padding: 1em 0em 1em 1.4em;
text-align: center;
width: 79%;
}
.top-nav ul li a i{
display: block;
margin-top: 1em;
color: #FFF;
font-size: 11px;
font-style: italic;
}
.top-nav ul ul {
display: none;
left:0;
float: left;
position: relative;
}
.top-nav ul ul li {
float:none;
width:200px;
z-index: 1;
}
.top-nav ul ul li a {
padding: 5px 5px;
}
.top-nav ul li:hover > ul {
display:block;
HTML CODE:
<div class="top-nav">
<span class="menu"><img src="images/menu.png" alt=""></span>
<ul class="nav1" style="margin-top: .5em;">
<li class="hvr-sweep-to-bottom active">Home</li>
<li class="hvr-sweep-to-bottom" style="width:22%;">Fleet Management
<ul class="level_1">
<li>Basic</li>
<li>Basic Plus</li>
<li>Ultra</li>
<li>Ultra Plus</li>
</ul>
</li>
<li class="hvr-sweep-to-bottom">Broker Agency</li>
<li class="hvr-sweep-to-bottom">Drivers</li>
<li class="hvr-sweep-to-bottom">Contact</li>
<div class="clearfix"> </div>
</ul>
Add position: absolute to the menu. Also make sure to update the top and background:
.top-nav ul ul {
display: none;
left: 0;
/* Changes below */
float: none;
position: absolute;
top: 62px;
background: #bb1e10;
}
Preview
Update
Add this to the .header:
.header {
position: relative;
z-index: 10000;
}
Fixes the last links:
Exactly as Praveen says, you need to make the nav absolutely positioned. Make sure though, the container 'header' is relative positioned, else it will fill 40% of the whole screen.
check out this fiddle to see what i mean: https://jsfiddle.net/ho2sph79/
.header {
position:relative;
}
.top-nav {
position:absolute;
width:40%;
top:0;
right:0;
}
you can try this http://callmenick.com/post/slide-down-menu-with-jquery-and-css and as i noticed, your css for the dropdown doesnt have any transition elements. try the link i provided it may help you out regarding transitions

fluid width drop down menu

I'm having great difficultly designing a drop down menu with pure css, that has fluid width. The examples I've found all have a fixed width top menu. As soon as I make the top menu fluid width, the drop down doesn't work. Can anyone help me complete the code? I basically have 7 menu items including a blank middle one. Over the middle one I have an absolute positioned logo.
HTML
<div style="position:relative;">
<img style="position:absolute; width:14.28%; max-height:80px; margin-left: auto;margin-right: auto;left: 0;right: 0;" src="\adrenicon.jpg"/>
<nav>
<ul>
<li>Start Here</li>
<li>Destinations
<ul>
<li>Africa</li>
<li>Europe</li>
<li>America</li>
</ul>
</li>
<li>Features</li>
<li>&nbsp</li>
<li>Activities</li>
<li>Planner</li>
<li>Contact</li>
</ul>
</nav>
</div>
CSS:
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
nav li {
float: left;
width:14.28%;
text-align: center;
line-height: 50px;
display: inline-block;
position: relative;
}
nav li a {
font-weight: bold;
color: hotpink;
text-align: center;
padding: 0px;
text-decoration: none;
-webkit-transition: color 1s;
transition: color 1s;
}
nav li a:hover {
color: #111;
}
nav ul li ul {
position: absolute;
display: none;
background-color: #f9f9f9;
min-width: 160px;
}
Thanks for any help.
first you need to set overflow:visible to the main ul ( nav ul )
then, because you set a width of 14.28% on the nav ul li you need to set a width of 100% to the second level of li ( nav ul li ul li ) so they don't get on top of eachoter and each stays on a separate row
and because the li has float:left; you need to set float:left;width:100% on the nav ul also.
then on hover on li change display:none to display:block on the second ul
see below snippet. let me know if it works
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: visible;
background-color: #333;
float:left;
width:100%;
}
nav li {
float:left;
width:14.28%;
text-align: center;
line-height: 50px;
position: relative;
}
nav li a {
font-weight: bold;
color: hotpink;
text-align: center;
padding: 0px;
text-decoration: none;
-webkit-transition: color 1s;
transition: color 1s;
}
nav li a:hover {
color: #111;
}
nav ul li ul {
position: absolute;
display: none;
background-color: #f9f9f9;
min-width: 160px;
}
nav ul li ul li {
width:100%;}
nav ul li:hover > ul{
display:block;
}
nav ul ul ul {
right:-100%;
top:0
}
<div style="position:relative;">
<img style="position:absolute; width:14.28%; max-height:80px; margin-left: auto;margin-right: auto;left: 0;right: 0;" src="http://placehold.it/100x100.jpg"/>
<nav>
<ul>
<li>Start Here</li>
<li>Destinations
<ul>
<li>Africa
<ul>
<li>Kenya</li>
<li>Tanzania</li>
</ul>
</li>
<li>Europe
<ul>
<li>Spain</li>
<li>France</li>
</ul>
</li>
<li>America</li>
</ul>
</li>
<li>Features</li>
<li>&nbsp</li>
<li>Activities</li>
<li>Planner</li>
<li>Contact</li>
</ul>
</nav>
</div>
Edited also for 3rd level of ul .
code : ul ul ul { right:-100%;top:0;}

separate main nav links from sub nav links in css?

I'm trying to create a dropdown menu for my personal website but something doesn't seem to go right.
HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li><li>
League</li><li>
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
Contact</li>
</ul>
</nav>
</header>
CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li {
display: inline-block;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
height: 20px;
border-radius: 2px;
}
The last few lines of code are the problem I think. The hover part covers every line-item that is within the .nav , but I don't know how to seperate the main navigation links from the sub navigation links (which should drop down) in css.
Can anyone explain to me what code I should add to let it work?
thanks.
I modified your complete code:
Here is it, There are several modification. This is may be helpful for you. You need to hide your drop-down option first and find out the time when firing it out and also how to fire.
And one important thing, you have to set your drop-down options as absolute, so that it is the child of some main option/ menu.
Modified HTML:
<header class="mainheader">
<nav class="nav">
<ul>
<li>Home</li>
<li>
League
</li>
<li>Dropdown
<ul class="nav-dropdown">
<li>bbva</li>
<li>barclays premier league</li>
</ul>
</li>
<li>Contact</li>
</ul>
</nav>
</header>
Modified CSS:
.mainheader, .header-text, .header-text-soccer {
background-color: green;
margin-left: 60px;
margin-right: 60px;
margin-top: 20px;
height: 60px;
border-radius: 6px;
position: relative;
}
.mainheader nav ul li a {
text-decoration: none;
color: white;
}
.mainheader nav ul li ul{
display: none;
}
.mainheader nav ul li {
display: inline-flex;
padding: 20px;
color: white;
}
.nav ul li:hover {
background-color: #41a608;
border-radius: 2px;
}
.nav ul li:hover ul{
background: #aaa none repeat scroll 0 0;
display: block;
margin-left: -20px;
padding: 0;
position: absolute;
top: 60px;
width: 200px;
}
.mainheader nav ul li ul li{
box-sizing: border-box;
color: white;
display: inline-block;
padding: 20px;
width: 100%;
}
I suppose this is what you need:
https://jsfiddle.net/8f2hvdfh/1/
Your CSS was a mess. Check out a guide on how to make CSS dropdown menus: http://www.w3schools.com/css/css_dropdowns.asp
This gives you the basic setup:
nav ul ul {
position:absolute;
display:none;
padding-left:0;
}
nav ul li {
display:inline-block;
height:60px;
}
nav ul ul li {
display:block;
}
nav ul li a {
text-decoration:none;
color:white;
display:block;
padding:21px;
}
nav ul li:hover ul {
display:block;
}
The rest is bells and whistles. Good luck.

Second level menu behaving abnormal

I have a menu created for my website in which I have second level menu aswell but the problem is that the second level menu has some problems:
It's size is bigger
It's menu items are floating right
It's going into another first level menu item's territory
I want to solve these problems but I am not able to do it on my own.
HTML:
<header>
<div class="welcome_area">
<p>Welcome, <b>Arkam Gadet</b>
</p>
</div>
<div class="menu">
<nav>
<ul style="z-index: 20;">
<li> My Profile
<ul style="display: none; background-color: #eee; box-shadow: 0px 0px 2px 3px #bbb; z-index: 1;">
<li>My Questions
</li>
<li>Settings
</li>
</ul>
</li>
<li>Inbox
</li>
<li>Notifications
</li>
</ul>
</nav>
</div>
</header>
CSS:
header {
background-color: #eee;
height: 45px;
box-shadow: 0px 2px 3px 1px #bbb;
}
a {
color: black;
text-decoration: none;
}
h2 {
color: #f79a1d;
}
.welcome_area {
float: left;
margin-left: 5%;
}
.menu {
float: right;
margin-right: 5%;
}
.menu nav > ul {
position: relative;
}
.menu nav ul li {
display: inline;
padding: 5px;
}
.menu nav ul li a {
padding: 2px;
}
.menu nav ul li a:hover {
background: #eee;
border: 0;
border-radius: 3px;
box-shadow: 0px 0px 2px 1px #000;
}
.menu nav > ul ul {
position: absolute;
left: 0;
}
.menu nav > ul li > ul li {
display: block;
}
Demonstration.
As you can see in the fiddle the items are floating towards right in the second level menu, I want them to
Float left the second level menu items
Shorten the second level menu's width
Send them back of the navbar.
Prevent it from going into another first level menu item's place.
Here are my responses to your issues and a corresponding Fiddle.
1) Float left the second level menu items
Removed padding.
.menu nav ul { padding:0px; }
Also repositioned drop-downs (tweak this as neccessary):
.menu nav > ul ul {
position: absolute;
left: 5px;
top:22px;
}
2) Shorten the second level menu's width
Was this satisfied by #1?
3) Send them back of the navbar.
Added position and z-index.
.menu nav ul li a {
position:relative;
padding: 2px;
z-index:5;
}
This positions the drop-downs behind the main <a>s.
However, if you want the drop-downs to come from behind the actual menu bar (gray bar), you'll need to restructure things.
4) Prevent it from going into another first level menu item's place.
I'm not sure what this means. Possible to clarify?
Add this to your css
.menu nav ul li ul {
padding:0px;
margin-left:45px;
}
Demo