I'd like for the menu sub menu to show 10 pixels underneath the menu, i can achieve that using margin-top on the ul, but then i cant move my mouse down to the sub menu because there is a gap. There are posts very similar to this but i could't extract an answer from them. Like this one
Space between menu and drop down menu
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
margin-top: 18px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2 long lel</li>
<li>Sub Menu 3 really bare long mad</li>
<li>Sub Menu 4 dvg</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg</li>
<li>sdfg</li>
<li>sdfgsdfgsdfgsdfg</li>
<li>sdfgsdfgsdfgsdfgsdfg</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf</li>
<li>sfdgsdfgsdfgl</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1</li>
<li>Sub Deep 2</li>
<li>Sub Deep 3</li>
<li>Sub Deep 4</li>
</ul>
</li>
<li>Deep Menu 2</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages</li>
<li class="point">light version</li>
</ul>
UPDATE:
Now that you gave the reference, the hover menu is not actually distant from the li itself, but it is positioned right below it. On the example site the li has a height bigger than the text within and has position: relative; on it.
The dropdown is absolute positioned right below this bigger <li> element with a top: 100%; that way it is distant from the text that triggers the dropdown.
Check the updated Snippet bellow with an updated solution.
Margins are not 'hoverable', and therefore the hover selector is not triggered. One way to keep it distant whilst 'hoverable' is to use padding instead of margins.
So you could change your .lmao li ul, although I wouldn't advise adding style to tags as a CSS best practice, I usually adopt a CSS naming convention such as BEM, SMACSS, among others.
/* Reset the ul style */
ul {
list-style: none;
padding: 0;
margin: 0;
}
deepMenu {
background: black !important;
margin-left: 100px !important;
position: absolute !important;
}
.lmao {
width: 100%;
text-align: center;
}
.lmao li {
display: inline-block;
background-color: white;
padding: 15px;
position: relative;
padding: 20px;
}
.lmao li a {
text-decoration: none;
color: black;
}
.lmao li a:hover {
text-decoration: none;
color: #f38763;
}
.lmao li ul {
display: none;
position: absolute;
border-top: 5px solid black;
top: 100%;
min-width: 200px;
}
.lmao li ul li {
display: none;
border-top: 0.1px solid #F2F2F2;
padding: 10px 40px 10px 10px;
margin: 0;
position: relative;
z-index: 9999999;
background: white;
font-size: 8pt;
line-height: 24px;
text-align: left;
}
.lmao li:hover > ul,
.lmao li:hover > ul li {
display: block;
}
<ul class="lmao">
<li class="point1">home
<ul>
<li>Sub Menu 1
</li>
<li>Sub Menu 2 long lel
</li>
<li>Sub Menu 3 really bare long mad
</li>
<li>Sub Menu 4 dvg
</li>
</ul>
<li class="point">features
<ul>
<li>sdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li>sdfg
</li>
<li>sdfgsdfgsdfgsdfg
</li>
<li>sdfgsdfgsdfgsdfgsdfg
</li>
</ul>
<li class="point layout">Layouts
<ul>
<li>sfdgsdfgsdfgsdfgsdfgdfgsdgsdf
</li>
<li>sfdgsdfgsdfgl
</li>
<li>dfsgsdfgsdfgsdfgsdfgsdfgsdfg
</li>
<li class="arrow">sfgsdfg
<ul class="deepMenu">
<li>Deep Menu 1
<ul>
<li>Sub Deep 1
</li>
<li>Sub Deep 2
</li>
<li>Sub Deep 3
</li>
<li>Sub Deep 4
</li>
</ul>
</li>
<li>Deep Menu 2
</li>
</ul>
</li>
</ul>
</li>
<li class="point">pages
</li>
<li class="point">light version
</li>
</ul>
body {
background-color: #cac3bc
}
nav {
float: left;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background-color: #fff;
margin-top: 10px;
padding: 0 20px;
list-style: none;
position: relative;
display: inline-table;
margin-right: -80px;
}
nav ul li {
float: left;
}
nav ul li:hover {
border-bottom: 5px solid #f5aa65;
color: #fff;
}
nav ul li a:hover {
color: #000;
}
nav ul li a {
display: block;
padding: 15px 15px;
font-family: 'PT Sans', sans-serif;
color: #000;
text-decoration: none;
}
nav ul ul {
background-color:#fff;
border-radius: 0px;
padding: 0;
position: absolute;
top: 100%;
box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #000;
}
nav ul ul:before {
content: "";
display: block;
height: 20px;
position: absolute;
top: -20px;
width: 100%;
}
<body>
<nav>
<ul>
<li>One
<ul>
<li>A</li>
<li>B
</ul>
</li>
<li>Two
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
</li>
<li>Three
<ul>
<li>A</li>
<li>B</li>
</ul>
</li>
<li>Four</li>
</ul>
</nav>
</body>
Related
I have created my nav bar which was working fine but now i tried to add sub menu in my navbar and its not showing sub menu on hover. kindly check and correct me.
First I added <ul> in my <li> tag then I added css to hide nested <ul> then I tried to show <ul> on hover <li>
*{
margin: 0;
padding: 0;
}
nav{
background-color: red;
}
ul{
background-color: purple;
width: 50%;
}
nav ul li {
list-style: none;
padding: 5px;
display: inline-block;
}
nav ul li a{
text-decoration: none;
color:black;
font: bold 12px Arial;
}
nav ul li:hover{
background-color: blue;
color: red;
}
nav ul li:hover a{
color: red;
}
ul li ul {
display: none;
position:absolute;
}
nav ul li:hover ul {
display:block;
}
<nav>
<ul>
<li> Home</li>
<li> About Us</li>
<li> Contact Us</li>
<li> Privacy Policy</li>
<li>
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
<li>Submenu 4</li>
</ul>
</li>
</ul>
</nav>
Looks like your <li> wrap is incorrect!
here is the fiddle
After Privacy Policy you have created another <li> that shouldn't be needed. you have to wrap the sub-menus with in privacy policy tag not a new one that is one of the reason why the css was not showing data as expected and you were almost there regarding CSS I just fixed it for you! hope it helps.
* {
margin: 0;
padding: 0;
}
nav {
height: 30px;
}
nav ul {
display: block;
position: relative;
z-index: 100;
}
nav ul li {
float: left;
list-style: none;
margin: 0;
padding: 0;
}
nav ul li ul {
display: none;
}
nav ul li a {
width: 100px;
height: 30px;
display: block;
text-decoration: none;
text-align: center;
line-height: 30px;
background-color: black;
color: white;
}
nav ul li a:hover {
background-color: red;
}
nav ul li:hover ul {
position: absolute;
top: 30px;
display: block;
width: 100px;
}
nav ul li:hover ul li {
display: block;
}
<nav>
<ul>
<li> Home</li>
<li> About Us</li>
<li> Contact Us</li>
<li> Privacy Policy
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
</ul>
</li>
</ul>
</nav>
Why don't you start from this working snippet and try to change data according to your needs :)
HTML Sub-Nav
*{
margin: 0;
padding: 0;
}
nav{
background-color: red;
}
ul{
background-color: purple;
width: 50%;
}
nav ul li {
list-style: none;
padding: 5px;
display: inline-block;
}
nav ul li a{
text-decoration: none;
color:black;
font: bold 12px Arial;
}
nav ul li:hover{
background-color: blue;
color: red;
}
nav ul li:hover a{
color: red;
}
ul li ul {
display: none;
position:absolute;
}
nav ul li:hover ul {
display:block;
}
<nav>
<ul>
<li> Home</li>
<li> About Us</li>
<li> Contact Us</li>
<li> Privacy Policy</li>
<li>
test
<ul>
<li>Submenu 1</li>
<li>Submenu 2</li>
<li>Submenu 3</li>
<li>Submenu 4</li>
</ul>
</li>
</ul>
You have to add an anchor tag in the sub nav you have created. Because currently those sub-tabs are created but are not associated with any super-tab.
Subnav
So add this above your sub-nav code. You are good to go.
nav#primary_topmenu {
position: fixed;
z-index: 5;
width: 1300px;
top:0%;
text-align: center;
}
#topnav{
height: 85px;
background: rgba(29, 15, 6, 0.7);
width: 1300px;
}
#logotop img {
float:left;
margin-top: 5px;
}
nav#primary_topmenu a {
text-decoration: none;
text-indent: -9999px;
color: #fff;
}
nav#primary_topmenu li {
display:block;
font-size: 1.2em;
padding: 1em;
font-weight: 900;
font-family: 'Sorts Mill Goudy', "MS Mincho", serif;
text-align: center;
height: 3em;
display:table-cell;
vertical-align: middle;
/*border: solid 1px #fff;*/
}
nav#primary_topmenu ul {
display: inline-block;
height: 85px;
box-shadow: 0 0 25px rgba(0,0,0,0.3);
background: rgba(29, 15, 6, 0.7);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#7E7E7E7E', EndColorStr='#7E7E7E7E');*/
}
nav#primary_topmenu li:hover {
border-bottom: 4px solid #cd4650;
}
nav#primary_topmenu a:hover {
color: #cd4650;
}
/*---- dropdown menu----*/
nav#primary_topmenu ul ul {
display: none;
position:fixed;
top:88px;
height:61px;
padding:0;
margin: 0;
}
nav#primary_topmenu ul ul li {
float:none;
display: block;
height:20px;
font-weight: normal;
font-family: 'Sorts Mill Goudy', "MS Mincho", serif;
border: 1px solid rgba(150,150,150,0.1);
box-shadow: 0 0 25px rgba(0,0,0,0.3);
background: rgba(29, 15, 6, 0.7);
}
nav#primary_topmenu ul li:hover > ul{ /*when hovering the parents please show the child*/
display:block;
padding:0;
margin: 0;
}
nav#primary_topmenu ul ul li a:hover {
list-style-type: none;
}
<div id="topnav">
<nav id="primary_topmenu">
<ul>
<div id="logotop"><img src="images/coincopy.png">
<li>
<a class="introduction" href="#primary_topmenu li">Home</a>
</li>
<li>
<a class="background" href="#background">Mission</a>
</li>
<li>
<a class="ira" href="#ira">Fund <br>Placement</a>
</li>
<li>
<a class="corporate" href="#corporate">Corporate <br>Finance</a>
</li>
<li>
<a class="investment" href="#investment">Renewable <br> Energy</a>
</li>
<li>
<a class="consulting" href="#consulting">Team</a>
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
</ul>
</li>
<li>
<a class="consulting" href="#consulting">Other <br>Services</a>
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
</ul>
</li>
<li>
<a class="consulting" href="#consulting">Licenses <br>& Compliance</a>
</li>
<li>
<a class="principal" href="#principal">Connections</a>
</li>
</div>
</ul>
</nav>
</div>
I try to align my submenu so that it is align exactly under the parents. Whenever I hover with the mouse to for example "Team" the submenu appear, but not align exactly where Team menu start.
I think it is because I have padding: 1em; at the nav#primary_topmenu li.
But then I have tried to add margin-left:-15px on nav#primary_topmenu ul ul in css, but it did not move.
How do I solve this? I tried to put padding: 0 and Margin:0 at the submenu li, but does not help...Please help me.
I think I got this figured out ;).
The problem appears to be the "padding: 1em;" at the "nav#primary_topmenu li". As you expected. It moved the list by 1em to the right.
Your own solution didn't work because "nav#primary_topmenu ul li:hover > ul" resets the margins to 0 and overwrites your solution.
So the solution was simple. Add the "margin-left: -1em;" to "nav#primary_topmenu ul li:hover > ul" instead of "nav#primary_topmenu ul ul".
This is the fiddle (fullscreen)
This is the fiddle with code
PS: I also did a little fix to the moving navigation (last line of the css)
HTML
<ul>
<div id="logotop"><img src="images/coincopy.png">
<li>
<a class="introduction" href="#primary_topmenu li">Home</a>
</li>
<li>
<a class="background" href="#background">Mission</a>
</li>
<li>
<a class="ira" href="#ira">Fund <br>Placement</a>
</li>
<li>
<a class="corporate" href="#corporate">Corporate <br>Finance</a>
</li>
<li>
<a class="investment" href="#investment">Renewable <br> Energy</a>
</li>
<li>
<a class="consulting" href="#consulting">Team</a>
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
</ul>
</li>
<li>
<a class="consulting" href="#consulting">Other <br>Services</a>
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
<li>Sub Menu 1</li>
<li>Sub Menu </li>
</ul>
</li>
<li>
<a class="consulting" href="#consulting">Licenses <br>& Compliance</a>
</li>
<li>
<a class="principal" href="#principal">Connections</a>
</li>
</div>
</ul>
</nav>
</div>
CSS
nav#primary_topmenu {
position: fixed;
z-index: 5;
width: 1300px;
top:0%;
text-align: center;
}
#topnav{
height: 85px;
background: rgba(29, 15, 6, 0.7);
width: 1300px;
}
#logotop img {
float:left;
margin-top: 5px;
}
nav#primary_topmenu a {
text-decoration: none;
text-indent: -9999px;
color: #fff;
}
nav#primary_topmenu li {
display:block;
font-size: 1.2em;
padding: 1em;
font-weight: 900;
font-family: 'Sorts Mill Goudy', "MS Mincho", serif;
text-align: middle;
height: 3em;
display:table-cell;
vertical-align: middle;
/*border: solid 1px #fff;*/
}
nav#primary_topmenu ul {
display: inline-block;
height: 85px;
box-shadow: 0 0 25px rgba(0,0,0,0.3);
background: rgba(29, 15, 6, 0.7);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#7E7E7E7E', EndColorStr='#7E7E7E7E');*/
}
nav#primary_topmenu li:hover {
border-bottom: 4px solid #cd4650;
}
nav#primary_topmenu a:hover {
color: #cd4650;
}
/*---- dropdown menu----*/
nav#primary_topmenu ul ul {
display: none;
position:fixed;
top:88px;
height:61px;
padding:0;
margin:0;
}
nav#primary_topmenu ul ul li {
float:none;
display: block;
height:20px;
font-weight: normal;
font-family: 'Sorts Mill Goudy', "MS Mincho", serif;
border: 1px solid rgba(150,150,150,0.1);
box-shadow: 0 0 25px rgba(0,0,0,0.3);
background: rgba(29, 15, 6, 0.7);
}
nav#primary_topmenu ul li:hover > ul{ /*when hovering the parents please show the child*/
display:block;
padding:0;
margin: 0;
margin-left: -1em; /*the dropdown displayed too much to the right because of the 1em padding in nav#primary_topmenu li. This moves the dropdown back by the same amount. */
}
nav#primary_topmenu ul ul li a:hover {
list-style-type: none;
}
nav#primary_topmenu ul li{
border-bottom: 4px solid transparent; /*prevents navigation from moving when applying the bottom border on hover*/
}
Im trying to do a sub-sub menu in a webpage. I tried following the help in this post: how do I make a sub sub menu with css? but to be honest i didnt understand what code i had to add in each class and when i tried it didnt show anything. Here is the code of the menu:
<div class="l7menu">
<ul class="dpdown">
<li class="mainlist">Hombres
<ul class="sub_menu">
Prueba
Here goes the sub-submenu
<ul>
<li> Item 1 </li>
<li> Item 2 </li>
</ul>
</ul>
</li>
</ul>
</div>
Also the CSS of the classes are these ones (The sub_menu and l7menu class dont have any style applied):
.mainlist {
border-bottom: 2px solid #EAD704;
background: none;
margin-left: 2px !important;
}
.mainlist:hover {
color: #EAD704 !important;
}
ul.dpdown {
float: right;
position: relative;
z-index: 1000;
}
ul.dpdown li {
font-weight: bold;
float: left;
zoom: 1;
display: inline;
line-height: 20px;
list-style: none outside none;
margin-left: -25px;
}
ul.dpdown a:hover {
color: #EAD704;
}
ul.dpdown a:active {
color: #FFFFFF;
}
ul.dpdown li a {
color: #e8e8e8;
display: block;
padding-bottom: 4px;
text-align: center;
width: 150px;
}
ul.dpdown li:last-child a {
border-right: none;
} /* Doesn't work in IE */
ul.dpdown li.hover, ul.dpdown li:hover {
color: black;
position: relative;
}
ul.dpdown li.hover a {
color: white;
}
/*
LEVEL TWO
*/
ul.dpdown ul {
width: 150px;
visibility: hidden;
position: absolute;
top: 100%;
left: 0;
}
ul.dpdown ul li {
font-weight: normal;
background: #333;
color: #000;
float: none;
}
/* IE 6 & 7 Needs Inline Block */
ul.dpdown ul li a {
background-color: #101010;
border-right: medium none;
display: inline-block;
margin-top: 2px;
padding: 10px 0;
width: 150px;
font-size: 13px;
color: #999999;
}
ul.dpdown ul li a:hover {
background-color: #222222;
}
/*
LEVEL THREE
*/
ul.dpdown ul ul {
left: 100%;
top: 0;
}
ul.dpdown li:hover > ul {
visibility: visible;
}
As always thank you very very much !
Here's a FIDDLE, I fixed your CSS a little.
Your HTML should look like this
<div class="l7menu">
<ul class="dpdown">
<li class="mainlist">Hombres
<ul class="sub_menu">
<li>Prueba</li>
<li>Here goes the sub-submenu
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</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 am trying to make a drop down menu using only CSS, but i'm having a hard time getting the dropdown menu the same size (width and height) as it's parent:
Working fiddle: HERE
The <nav> section from my HTML:
<nav>
<ul>
<li>Home</li>
<li>Menu With Menus
<ul>
<li>opt 1</li>
<li>opt 2</li>
<li>opt 3</li>
</ul>
</li>
<li>Whatnot</li>
</ul>
</nav>
The CSS:
nav ul {
position: relative;
display: inline-table;
list-style: none;
}
nav ul li {
float:left;
list-style-type: none;
}
nav ul li a {
background-color: #dae8ec;
color: rgb(233,78,31);
display: block;
font-weight: bold;
margin: 0 auto;
padding: 9px 18px 9px;
text-decoration: none;
border: 1px solid black;
border-radius: 2px;
}
nav ul ul {
display: none;
position: absolute;
top: 100%;
}
nav ul li:hover > ul {
display: block;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 7px 30px;
color: rgb(233,78,31);
}
nav ul li a:hover {
background: rgb(138, 92, 132);
color:#dae8ec;
}
Any suggestions? Thanks.
Js Fiddle Demo
<nav>
<ul>
<li>Home</li>
<li>Menu Withs
<ul>
<li>opt 1</li>
<li>opt 2</li>
<li>opt 3</li>
</ul>
</li>
<li>Whatnot</li>
</ul>
</nav>
Cheers !!