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>
Related
I wrote a code using different internet source and I ran into a problem every object that's in the bottom of the menu parts cannot be interacted the menu interferes everything below him where the dropdown falls . the hitbox of the menu seems to included the dropdown even when its not shown
body {
padding: 0;
margin: 0;
font-family: Arial;
font-size: 23px;
}
#nav {
background-color:1a1a1a;
opacity: 0.9;
}
#nav_wrapper {
width: 960px;
margin: 0 auto;
text-align: 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: 0px solid #222;
border-top: 0;
margin-left: -5px;
}
#nav ul ul li {
display: block;
}
#nav ul ul li a:hover {
color: #699;
}
.left-to-right {
text-align: left;
}
<body dir-"rtl"><div id="nav">
<div id="nav_wrapper">
<div>
<ul <ul dir="RTL">
<li> תרמילים
<ul class="left-to-right">
<!-- <li class="backpacks" id="firstlight-20l"> FirstLight 20L </li>
<li class="backpacks" id="firstlight-30l"> FirstLight 30L </li>
<li class="backpacks" id="firstlight-40l"> FirstLight 40L </li>-->
<li class="backpacks"> rotation180° Professional 38L Deluxe </li>
<li class="backpacks"> rotation180° Horizon 34L </li>
<li class="backpacks"> rotation180° Panorama 22L </li>
<!-- <li class="backpacks" id="rotation180-travel-away"> rotation180° Travel Away 22L </li>-->
<li class="backpacks" id="rotation180-trail"> rotation180° Trail 16L </li>
</ul>
</li>
<li> תיקי מצלמות ספורט
<ul class="left-to-right">
<li>GP 1 kit case
</li>
<li>GP 2 kit case
</li>
</ul>
</li>
<li> אביזרים
<ul class="left-to-right">
<li>r180º Panorama/Horizon Photo Insert
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
Help will be appreciated
edit:
the menu is working but everything below him in the area where the dropdown fals dosent
Need to select all sibling <li> elements on hover. Tried accepted answer here but it is not working. JSFiddle here
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu li:hover ~ .menu li{/*ON THIS HOVER NOT SHOWING ALL SIBLIING LIs*/
display: block !important;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a></li>
<li>Home</li>
<li>Portfolio</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
Your problem is the selector:
.menu li:hover ~ .menu li
A hidden element can't be hovered-over, which means that li:hover is never going to match an element. Also, the general-sibling combinator is trying to find (subsequent) siblings that are <li> elements descending from sibling .menu elements. Which matches no elements in the page.
Converting that to the following selector:
.menu:hover li ~ li
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu:hover li ~ li {
display: block;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a>
</li>
<li>Home
</li>
<li>Portfolio
</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu
</li>
<li>Sub Menu
</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
works; that said it will - because of the general sibling combinator - match only those <li> elements with a preceding <li> sibling, which means it will, and can, never show the first <li>.
So, instead, I'd suggest using:
.menu:hover li
.menu {
margin: 0;
padding: 0;
list-style: none;
overflow: hidden;
;
background-color: #777;
}
.menu li {
float: none;
display: none;
}
.menu li a {
display: block;
padding: 10px 20px 10px 20px;
text-decoration: none;
color: #bbb;
}
.menu li a:hover {
color: #fff;
}
.menu .btn {
display: block;
cursor: pointer;
}
.menu:hover li {
display: block;
}
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
<ul class="menu">
<li class="btn"><a>☰</a>
</li>
<li>Home
</li>
<li>Portfolio
</li>
<li>Contact
<ul class="sub-menu">
<li>Sub Menu
</li>
<li>Sub Menu
</li>
</ul>
</li>
</ul>
<!--NEED SOLUTION WITHOUT ALTERING HTML -->
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/
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