(source: torrent-invites.com)
I want to make pure CSS multi level menu like the picture above. I have tried some tutorial but its not working for me. Menu "xxxxx" and "yyyyy" appear below menu "bbbbb" for my CSS code below.
What I want to make is 3 level menu like the picture above.
This is my HTML for the menu:
<span id="nav">
<ul>
<li>ssss
<ul>
<li>aaaaa</li>
<li>bbbbb
<ul>
<li>xxxxx</li>
<li>yyyyy</li>
</ul>
</li>
</ul>
</li>
<li>ttttt</li>
<li>uuuuu</li>
</ul>
</span>
And this is my minimized CSS code:
li {
list-style:none !important;
}
#nav, #nav ul {
list-style: none;
padding:0;
margin:0;
}
#nav li {
line-height:20px;
float:left;
}
#nav li ul{
display:none;
}
#nav ul li ul {
margin-top:-3em;
margin-left:7em;
}
#nav ul li:hover ul {
z-index:99999;
display:list-item !important;
position:absolute;
margin-top:2px;
margin-left:0px;
padding: 5px 15px;
background: #8ac312;
}
#nav ul li:hover ul li {
float:none;
padding: 2px 0px;
}
#nav ul li:hover ul li > a:before {
content: '» ';
}
Any help would be very appreciated to make my CSS code working like the illustration picture above. Thanks.
I think your problem is position relative and absolute. I remove your style and do on my own (simpler, uglier). Code is here jsFiddle
And the code is:
CSS:
ul { padding:0; margin:0; }
li { list-style:none; }
li > ul { display: none; }
li:hover > ul { display: block; }
.lvl1 li { margin-right: 10px; display: inline; position:relative; }
.lvl2 { position: absolute; }
.lvl2 li { position: relative; }
.lvl3 { position: absolute; top:0px; left: 50px; }
HTML:
<span id="nav">
<ul class='lvl1'>
<li>ssss
<ul class='lvl2'>
<li>aaaaa</li>
<li>bbbbb
<ul class='lvl3'>
<li>xxxxx</li>
<li>yyyyy</li>
</ul>
</li>
</ul>
</li>
<li>ttttt</li>
<li>uuuuu</li>
</ul>
</span>
I've edited your code a bit ... check this fiddle http://jsfiddle.net/kau5h/
li {
list-style:none !important;
position:relative;
}
#nav, #nav ul {
list-style: none;
padding:0;
margin:0;
}
#nav li {
line-height:20px;
float:left;
}
#nav li a {display:block;}
#nav li ul{
display:none;
z-index:99999;
/*display:list-item !important;*/
position:absolute;
/*margin-top:2px;*/
margin-left:0px;
background: #8ac312;
}
#nav li ul ul {left: 100%; top:0;}
#nav ul li ul {
/*margin-top:-3em;
margin-left:7em;*/
}
#nav ul li:hover > ul {
display: block;
}
#nav ul li:hover ul li {
float:none;
/*padding: 2px 0px;*/
}
#nav ul ul li {
padding: 5px 15px;
display: block;
}
#nav ul ul li > a:before {
/*content: '» '; */
}
Related
Can anyone tell me what's wrong with my code below? I'm trying to make the menu show the list when hover over each link, but it's not working for some reason. I have already tried .menu ul ul: hover {visibility: visible; } and it didn't work.
Check my code and thank you in advance.
.menu {
width: 100%;
height: 50px;
background-color: #222;
font-family: 'Arial';
}
.menu ul {
list-style: none;
position: relative;
}
.menu ul li {
width: 150px;
float: left;
}
.menu a {
padding: 15px;
display: block;
text-decoration: none;
text-align: center;
background-color: #222;
color: #fff;
}
.menu ul ul {
position: absolute;
visibility: hidden;
}
.menu ul li ul:hover {
visibility: visible;
}
.menu a:hover {
background-color: #f4f4f4;
color: #fff;
}
<nav class="menu">
<ul>
<li>test1</li>
<li>test2</li>
<ul>
<li>test3</li>
<li>test4</li>
</ul>
<li>test5</li>
<ul>
<li>test6</li>
<li>test7</li>
<li>test8</li>
</ul>
<li>test9</li>
</ul>
</nav>
I have slightly modified your code. Sub-nav UL are now nested within the required LI. When you hover over "test2" nav it will show the sub-nav.
The CSS line below was modified too. Instead of using :hover on the sub-nav UL the code will now target the LI with the sub-nav and display the required one.
.menu ul li ul:hover {
to
.menu ul li:hover > ul {
*{
margin:0;
padding:0;
}
.menu{
width:100%;
height:50px;
background-color:#222;
font-family:'Arial';
}
.menu ul{
list-style:none;
position:relative;
}
.menu ul li{
width:150px;
float:left;
}
.menu a{
padding:15px;
display:block;
text-decoration:none;
text-align:center;
background-color:#222;
color:#fff;
}
.menu ul ul{
position:absolute;
visibility:hidden;
}
/*CSS modified here: when you hover over LI with sub-nav, it will display the UL in it.*/
.menu ul li:hover > ul{
visibility:visible;
border:1px solid #ff0000;
}
.menu a:hover{
background-color:#f4f4f4;
color:#fff;
}
<body>
<nav class="menu">
<ul>
<li>test1</li>
<li>test2
<!-- nested UL in LI -->
<ul>
<li>test3</li>
<li>test4</li>
</ul>
</li>
<li>test5
<!-- nested UL in LI -->
<ul>
<li>test6</li>
<li>test7</li>
<li>test8</li>
</ul>
</li>
<li>test9</li>
</ul>
</nav>
</body>
</html>
Hi There can anyone help me i try to create a dropdown submenu but it doesn't work for me.
I dont know how to reate a nice menu.
example:
When i hover over "massages" then the menu must come down and show the submenu.
css here
.menu{
width:821px;
height:42px;
margin:0px;
background:url(images/menu.gif) no-repeat left;
}
.menu ul{
list-style:none;
padding:0 0 0 15px;
margin:0px;
}
.menu ul li{
display:inline;
}
.menu ul li ul{
display:inline;
}
.menu ul li a{
float:left;
height:42px;
border:none;
padding:0 15px 0 15px;
text-decoration:none;
color:#fff;
line-height:42px;
font-size:14px;
}
.menu ul li.aktivni-active a{
float:left;
height:42px;
border:none;
padding:0 15px 0 15px;
text-decoration:none;
line-height:42px;
font-size:14px;
Html:
<div class="menu">
<ul>
<li class="aktivni-active">Home</li>
<li>Massages</li>
<ul>
<li>Aanbiedingen</li>
</ul>
<li>Aanbiedingen</li>
<li>Prijzen</li>
<li>Agenda</li>
<li>Contact</li>
</ul>
</div>
Can anyone explane me how to create a dorpdown submenu on "Massages"
Thnx
Check with the below link.
Fiddle
/* Menu Dropdown */
ul#menu, ul#menu ul.sub-menu {
padding:0;
margin: 0;
}
ul#menu li, ul#menu ul.sub-menu li {
list-style-type: none;
display: inline-block;
}
/*Link Appearance*/
ul#menu li a, ul#menu li ul.sub-menu li a {
text-decoration: none;
color: #fff;
background: #666;
padding: 5px;
display:inline-block;
}
/*Make the parent of sub-menu relative*/
ul#menu li {
position: relative;
}
/*sub menu*/
ul#menu li ul.sub-menu {
display:none;
position: absolute;
top: 30px;
left: 0;
}
ul#menu li ul.sub-menu a {
width:150px;
}
ul#menu li:hover ul.sub-menu {
display:block;
}
/* Top Nav Background Hover */
ul#menu li a:hover {
background:#000;
}
ul#menu li ul li a:hover {
background:#999;
}
/* 3rd level nav */
ul#menu li ul.sub-menu li ul {
display:none;
position: absolute;
top: 0px;
left: 115px;
width: 100px;
}
/* show the 3rd level when the second is hover */
ul#menu li ul.sub-menu li:hover ul {
display:block;
}
/* Menu Dropdown */
You should change your markup, as far as I know submenu should be part of list item it refers to
<ul>
<li class="simple-item">item</li>
<li class="submenu">item
<ul class="submenu-goes-inside-li">
<li class="simple-item">item</li>
<li class="simple-item">item</li>
<li class="simple-item">item</li>
</ul>
</li>
</ul
In your case submenu is separated from list items.
Using the same structure you have just add class to the drop menu,
set ul inside the dropMenu to display none, then to display on however. You can use css3 or jquery to make it have a nice animation or toggle.
<div class="menu">
<ul>
<li class="aktivni-active">Home</li>
<li class="dropMenu">Massages</li>
<ul>
<li>Aanbiedingen</li>
</ul>
<li>Aanbiedingen</li>
<li>Prijzen</li>
<li>Agenda</li>
<li>Contact</li>
</ul>
</div>
CSS
.menu ul{
display:none
}
.menu:hover ul{
display:block;
}
if you want some better just use jquery http://api.jquery.com/toggle/
I want to build a simple CSS dropdown menu. It works if I use absolute positioning, but starts to push down the content if I use relative positioning. What is the reason for this? Using absolute positioning for the DIVs menu and content is not an option for me unfortunately.
HTML:
<div id="menu">
<ul>
<li class="topmenu">
Top 1
<ul>
<li class="submenu">Sub 1</li>
<li class="submenu">Sub 2</li>
</ul>
</li>
</ul>
</div>
<div id="content">
Test
</div>
CSS:
#menu {
position:relative;
}
#menu ul {
list-style-type:none;
list-style-image:none;
margin:0px;
padding:0px;
}
#menu li.topmenu {
float:left;
}
.topmenu a {
float:left;
width:110px;
}
.topmenu ul{
display:none;
}
.submenu a{
width:110px;
clear:both;
}
.topmenu:hover ul {
display:block;
z-index:10;
}
#content {
display: block;
clear: both;
z-index: 1;
}
I've simplified the code, removed the horrible floats and substituted with display: inline-block and fixed the positioning issue.
(Demo)
#menu ul {
list-style:none;
margin:0px;
padding:0px;
font-size: 0px;
}
#menu li {
font-size: 1rem;
}
#menu > ul > li {
display: inline-block;
}
#menu ul ul {
display: none;
}
#menu ul li:hover ul {
display: block;
position: absolute;
}
#menu a {
display: inline-block;
width:110px;
}
I have been trying to add a drop down menu to this code but always seem to get turned around. I just want a basic look to the subnav with a simple rollover effect. Every time i try different code it uses home image in the drop down menu and will not disappear when it is not hovered over. Ideas?
HTML:
<ul class="navbar">
<li class="navbar1">Home
<ul class="subnav">
<li>Menu 1 </li>
<li>Menu 2 </li>
</ul>
</li>
</ul>
CSS:
ul.navbar {
width:1000px;
list-style:none;
height:40px;
}
ul.navbar li {
display:inline;
}
ul.navbar li a {
height:40px;
float:left;
text-indent:-9999px;
}
/* Home 0 */
ul.navbar li.navbar1 a {
width:86px;
background:url(../pelican%20outfitters/navbar2.fw.png)
no-repeat 0 0;
}
ul.navbar li.navbar1 a:hover {
background-position:0 -40px;
}
ul.navbar li.navbar1 a.current {
background-position:0 -80px;
}
HTML
<nav>
<ul class="navbar">
<li class="navbar1">Home
<ul class="subnav">
<li>Menu 1
</li>
<li>Menu 2
</li>
</ul>
</li>
</ul>
</nav>
CSS
nav {
margin: 20px auto;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul li
{
width:100px;
}
ul li ul li
{ width:200px;
}
nav ul {
font-size: 25px;
background: white;
padding: 0px;
border-radius: 10px;
border-style: solid;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content:"";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: black;
position:relative;
z-index:1;
}
nav ul li:hover a {
color: white;
position:relative;
z-index:1;
}
nav ul li a {
display: block;
padding: 15px 20px;
color: black;
text-decoration: none;
}
nav ul ul {
background: #000000;
border-radius: 0px 0px 10px 10px;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
float: none;
}
nav ul ul li a {
padding: 15px 20px;
}
nav ul ul li a:hover {
background: #2E2E2E;
border-radius: 10px;
}
Output:
Working Fiddle
You should delete the text-indent:-9999px and add this to your css
Delete row:
ul.navbar li a { text-indent:-9999px }
Css:
.navbar li ul {display:none;}
.navbar li:hover ul {display:block;}
Than you have a basic navbar with hidden subnavs.
From here you can try it with your image.
The demo is your code with the new code..
DEMO
More like you want is, dont delete the css.. but only add those 2 lines and this 1:
.navbar li:hover li a{ text-indent:1px; background:white; }
DEMO 2 (without your img (don't know what it is)).
Latest update after the fiddle comment:
You should specify your html and css.. a just added a class to the first link class="home" and to accomodations class="accomodations"
And changed it in the css..
/* Home */
ul.navbar li.navbar1 a.home {
width:86px;
background:url(http://s12.postimg.org/rszejjscd/navbar2_fw.png)
no-repeat 0 0;
}
/* Accomodations */
ul.navbar li.navbar2 a.accomodations {
width:220px;
background: url(http://s12.postimg.org/rszejjscd/navbar2_fw.png) no-repeat -86px 0;
}
DEMO 3
http://i.stack.imgur.com/OP0kc.jpg
the navigation menu i have created using the CSS and Html code is not working correctly.
The alignment of the navigation menu is not perfect i want in this way : http://i.stack.imgur.com/h4oPK.jpg
I want to convert this to CSS..
Please help
<style>
/* Targeting both first and second level menus */
#nav li {
list-style:none;
float: left;
position: relative;
}
#nav li a {
display: block;
padding: 8px 12px;
text-decoration: none;
}
#nav li a:hover {
background-color:red;
color:#FFF;
opacity:1;
}
/* Targeting the first level menu */
#nav {
top:150px;
min-width:850px;
background:#fff;
opacity:0.5;
display: block;
height: 34px;
z-index: 100;
position: absolute;
}
#nav > li > a {
}
/* Targeting the second level menu */
#nav li ul {
color: #333;
display: none;
position: absolute;
width:850px;
}
#nav li ul li {
display: inline;
}
#nav li ul li a {
background: #fff;
border: none;
line-height: 34px;
margin: 0;
padding: 0 8px 0 10px;
}
#nav li ul li a:hover {
background-color:red;
color:#FFF;
opacity:1;
}
/* Third level menu */
#nav li ul li ul{
top: 0;
}
ul.child {
background-color:#FFF;
}
/* A class of current will be added via jQuery */
#nav li.current > a {
background: #f7f7f7;
float:left;
}
/* CSS fallback */
#nav li:hover > ul.child {
left:0;
top:34px;
display:inline;
position:absolute;
text-align:left;
}
#nav li:hover > ul.grandchild {
display:block;
}
</style>
<ul id="nav">
<li>Home</li>
<li>
Products
<ul class="child">
<li>Hard Drives</li>
<li>Monitors</li>
<li>Speakers
<ul class="child">
<li>10 watt</li>
<li>20 watt</li>
<li>30 watt</li>
</ul>
</li>
<li>Random Equipment</li>
</ul>
</li>
<li>
Services
<ul class="child">
<li>Repairs</li>
<li>Installations</li>
<li>Setups</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
</ul>
Fixed. I think this is what you want http://dabblet.com/gist/2792978
Simply remove position: relative from #nav li and give it to #nav.