I have made a navigation menu bar and also two dropdown menus with 3 items each. My problem is that, below this menu, I have a slider, so when I hover my dropdown, two of the three items are hidden behind the slider.
How can I solve this?
My HTML:
<div id="nav">
<div id="nav_wrapper">
<ul>
<li>item #1
</li>
<li> item #2
</li>
<li> dropdown #1
<ul>
<li>dropdown #1 item #1
</li>
<li>dropdown #1 item #2
</li>
<li>dropdown #1 item #3
</li>
</ul>
</li>
<li> dropdown #2
<ul>
<li>dropdown #2 item #1
</li>
<li>dropdown #2 item #2
</li>
<li>dropdown #2 item #3
</li>
</ul>
</li>
<li> item #3
</li>
</ul>
</div>
</div>
My CSS:
#nav {
background-color: #222;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: left;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
I think the problem is on your z-index properties.
You need to set on #nav and #slider elements position and z-index properties.
#nav {
position: relative;
z-index: 2;
}
#slider{
position: relative;
z-index: 1;
}
That means the #nav menu will be front slider when you set a z-index property large than z-index on #slider. Have you attention that z-index doesn't work if you not set element position property like relative or absolute.
You can look this link for example - http://css-tricks.com/almanac/properties/z/z-index/
Related
In CSS, one submenu (Link 1, Link2, Link3) is available in this link. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_dropdown_navbar
I'm trying to create submenu (link 4.1, link4.2) under the above submenu as shown in below image.
how can I get this submenu. .
I've tried below. But this is overlapping. I'm newbie to CSS. please share your ideas
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="dropdown">Link 1</div>
<div class="dropdown-content">
Link 2
Link 3
</div>
Link 2
Link 3
</div>
</div>
This can be done by simple html/css work so just to give an idea here is a simple example:
ul {
list-style: none;
padding: 0;
margin: 0;
background: #000;
}
ul li {
display: block;
position: relative;
float: left;
background: #000;
}
li ul {
display: none;
}
ul li a {
display: block;
padding: 1em;
text-decoration: none;
white-space: nowrap;
color: #fff;
}
ul li a:hover {
background: #001;
}
li:hover>ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
}
li:hover a {
background: #000;
}
li:hover li a:hover {
background: #000;
}
ul ul ul {
left: 100%;
top: 0;
}
<ul>
<li>Home</li>
<li>First level Menu
<ul>
<li>Second Level</li>
<li>Second Level with third level
<ul>
<li>Third level</li>
<li>Third level</li>
</ul>
</li>
</ul>
</li>
</ul>
I have custom navbar, not any bootstrap or something else.
I tryed one tab is left and dropdowns are middle and one tab is right side.
But right side tab isnt inside navbar.
I dont understand why it is going out of navbar if it is in ul tag. Maybe someone can explain that.
HTML code:
<div id="nav">
<div id="nav_wrapper">
<ul>
<div id="left">
<li>
item #1
</li>
</div>
<div id="mid">
<li> dropdown #1
<ul>
<li>
dropdown #1 item #1
</li>
<li>
dropdown #1 item #2
</li>
<li>
dropdown #1 item #3
</li>
</ul>
</li>
<li> dropdown #2
<ul>
<li>
dropdown #2 item #1
</li>
<li>
dropdown #2 item #2
</li>
<li>
dropdown #2 item #3
</li>
</ul>
</li>
<li> dropdown #3
<ul>
<li>
dropdown #3 item #1
</li>
<li>
dropdown #3 item #2
</li>
<li>
dropdown #3 item #3
</li>
</ul>
</li>
</div>
<div id="right">
<li>
item #2
</li>
</div>
</ul>
</div>
<!-- Nav wrapper end -->
Style code:
body {
padding: 0;
margin: 0;
font-family: Arial;
font-size: 17px;
}
#nav {
background-color: #222;
}
#left{
float: left;
}
#mid{
margin-left: auto;
margin-right: auto;
text-align: center
}
#right{
float: right;
}
#nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
min-width: 200px;
}
#nav ul li {
display: inline-block;
}
#nav ul li:hover {
background-color: #333;
}
#nav ul li a, visited {
color: #CCC;
display: block;
padding: 15px;
text-decoration: none;
}
#nav ul li:hover ul {
display: block;
}
#nav ul ul {
display: none;
position: absolute;
background-color: #333;
border: 5px solid #222;
border-top: 0;
margin-left: -5px;
z-index: 1;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
Added html and style code here.
Problem is right side isnt in navbar.
I think in divs is problem.
Pls try
#nav_wrapper ul{
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display:flex;
}
and now you DON'T have to give float:left and float:right to the #left and #right divs; and your right div will be aligned on the right end.
OR
Add the following codes to your existing styles, to align your third item on the right end.
#nav{
background-color: #222;
overflow:hidden;
}
#mid{
float:left;
}
I have a menu bar on a hover it should display a submenu. I am displaying the sub menu but it moving entire main menu to side. I want the submenu out of the main menu, next to the main menu.
my HTML code
<div class="MenuBar">
<ul>
<li><img src="#"><br>text1</li>
<div id="submenu">
this is a test div
</div>
<li><img src="#"><br>text2</li>
<li><img src="#"><br>text3</li>
</ul>
CSS
#submenu {
display: none;
}
.MenuBar ul li a:hover #submenu {
display: block;
position: relative;
top: 20px;
}
I think this is what you are after. I have added classes to the lists, changed your id submenu to class and added submenu items to all lists.
.MenuBar ul li .submenu {
display: none;
}
.MenuBar ul li.men1:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
.MenuBar ul li.men2:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
.MenuBar ul li.men3:hover .submenu {
display: inline-block;
position: relative;
top: 20px;
}
<div class="MenuBar">
<ul>
<li class="men1">text1
<div class="submenu">
hovered 1st
</div></li>
<li class="men2">text2
<div class="submenu">
hovered 2nd
</div></li>
<li class="men3">text3<div class="submenu">
hovered 3rd
</div></li>
</ul>
Let me know if this was what you were after.
you can use following CSS for this:
if you want to show submenu in bottom of parent menu
.MenuBar ul li {
position: relative;
}
.MenuBar ul li:hover #submenu {
display: block;
position: absolute;
top: 100%;
left: 0px;
}
or if you want to show submenu in right of parent menu
.MenuBar ul li {
position: relative;
}
.MenuBar ul li:hover #submenu {
display: block;
position: absolute;
top: 0;
left: 100%;
}
Place the submenu div outside your lists. If you throw that inside a bunch of list item and play with display property, it will affect the list structure. Place that div outside the list item, position the submenu div with css so it always alignment to the respective menu item and them add your hover effect.
Change Html Like this:
<li>
<img src="#"><br>text1
<div id="submenu"><-----------------submenu must be child li
this is a test div
</div>
</li>
And Css Like This :
.MenuBar ul li a:hover + #submenu {<--------------use + selector
display: block;
position: relative;<-----Remove This
top: 20px;<------Remove This
margin-top: 20px;<----------Add This
margin-bottom: 10px;<-------Add This
}
Full Code:
#submenu {
display: none;
}
img {
width: 20px;
}
ul {
list-style: none;
}
.MenuBar ul li a:hover + #submenu {
display: block;
margin-top: 20px;
margin-bottom: 10px;
}
<div class="MenuBar">
<ul>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text1
</a>
<div id="submenu">
this is a test div
</div>
</li>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text2
</a>
</li>
<li>
<a href="#">
<img src="https://www.seeklogo.net/wp-content/uploads/2012/12/apple-logo-eps-logo-vector-400x400.png"><br>text3
</a>
</li>
</ul>
</div>
I'm trying to make a vertical dropdown menu but doesn't seem to work. It currently doesn't display any text, just a bar going across the top of the page. It is being pushed to be by by 115px for due to requirements. Here's the HTML:
<div id="wrapper">
<h1>Flags </h1>
<nav>
<ul>
<li>Introduction</li>
<li>History</li>
<li>National Flags</li>
<li>International Maritime Signal Flags
<ul>
<li>Maritime Signals: Letters</li>
<li>Maritime Signals: Numbers</li>
</ul>
</li>
</ul>
</nav>
Here is the CSS:
nav {
height:30px;
}
nav ul {
background-color: #5d2c2c;
padding: 0;
list-style: none;
position: relative;
bottom: 115px;
display: block;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: right;
bottom: 115px;
position: relative;
}
nav ul li a {
display: block; padding: 5px 5px;
color: #FFF; text-decoration: none;
text-align:right;
}
nav ul ul {
background: #5d2c2c; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
border-top: 1px solid #000;
border-bottom: 1px solid #575f6a;
position: relative;
}
The CSS needed a little work on
Try this FIDDLE it'll work
This was missing:
nav ul li:nth-child(4) ul { display:none; }
nav ul li:nth-child(4):hover ul { display:block; color:red; }
and bottom was removed from this one
nav ul li {
float: left;
position: relative;
}
I found this link the other day, it's an step by step guide with full examples, check it out: http://www.adam-bray.com/blog/91/Easy+HTML+5+%26+CSS+3+Navigation+Menu/
check this fiddle , a similar implementation
<nav>
<ul>
<li class="header">
People
<ul class="content">
<li>Sub 1</li>
<li>Sub 2</li>
</ul>
</li>
<li class="header">
Animals
<ul class="content">
<li>Sub 1</li>
<li>Sub 2</li>
</ul>
</li>
</ul>
</nav>
nav > ul{}
nav > ul > li{float:left;margin:0 5px;background:#cc3333;}
.header li a{background:#eee;color:#cc3333;}
.header li a:hover{color:#fff;background:#cc3333;}
ul{padding:0;}
li{list-style-type:none;}
a{color:#fff;text-decoration:none;padding:5px;display:block;text-align:center;}
.content{
display:none;
}
.header:hover > .content{display:block;}
I'm having trouble with z-index in IE 7. The problem is that the menu items are in 2 rows. If any of first row item has sub-menu, the IE7 won't let you hover it. The problem is caused by IE7 only.
Here's my code:
<div id="wrapper">
<div id="main-nav">
<ul class="main-menu" id="menu-header-menu">
<li class="menu-item">item 1
<ul class="sub-menu">
<li class="menu-item"> sub item
<ul class="sub-menu">
<li class="menu-item">sub sub item</li>
<li class="menu-item">sub sub item</li>
</ul>
</li>
</ul>
</li>
<li class="menu-item">item 2</li>
<li class="menu-item">item 3</li>
<li class="menu-item"> test item
<ul class="sub-menu">
<li class="menu-item">sub sub item</li>
<li class="menu-item">sub sub item</li>
</ul>
</li>
</ul>
</div>
</div>
CSS:
#wrapper {
width:250px;
margin:0 auto;
}
#main-nav {
background-color:orange;
padding: 0 10px;
clear: both;
display: block;
float: left;
width: 100%;
}
#main-nav ul {
list-style: none;
margin: 0 0 0 -0.8125em;
padding-left: 0;
}
#main-nav li {
float: left;
position: relative;
}
#main-nav a {
color:#737373;
display: block;
line-height: 2.333em;
padding: 0 1.2125em;
text-decoration: none;
}
#main-nav ul ul {
display: none;
float: left;
margin: 0;
position: absolute;
top: 2.333em;
left: 0;
width: 188px;
z-index: 999;
}
#main-nav ul ul ul {
left: 100%;
top: 0;
}
#main-nav ul ul a {
background: yellow;
height: auto;
line-height: 1.4em;
padding: 10px 10px;
width: 168px;
}
#main-nav li:hover > a,
#main-nav a:focus {
color: #373737;
}
#main-nav ul li:hover > ul {
display: block;
}
Here you can see the problem. When you hover on the item 1, it does not let me hover its sub item which has yellow background.
Easy fix. Add this to the bottom of your css code:
#main-nav ul li:hover {z-index:9999;}
The problem is that your element needed a higher z-index upon hovering, not before.
Here's a live link to a demo I uploaded. Works on both ie7 and ff/chr/saf:
http://sotkra.com/stackoverflow/ie7zindex/index.html
I nonetheless suggest you simplify your code, it's too clunky. There is a tiny bug where once you hover your 3rd layer menu, exit and then re-enter, the yellow background will be there. Should be fixed with a proper cleanup of your html/css
Cheers
G