I created a code for a drop down menu but when ever I hover over the drop down menu it will open all and not just the one hovered.
Heres my html:
<div class='menuTitle'>
Medical
<div class='menuContent'>
Test<br />
Test2<br />
Test<br />
</div>
</div>
<div class='menuTitle'>|</div>
<div class='menuTitle'>
Bro
<div class="menuContent">
test<br />
comone<br />
</div>
</div>
and my CSS:
.menuTitle {
display: inline-block;
}
.menuContent {
position: absolute;
width: 100px;
background-color: gray;
display: none;
text-align:center;
}
Are your links test, test2 and test? If so you have to put them in seperate divs, better still use ul and li for navigation. You can also use a generator for this http://cssmenumaker.com/
Try:
<div class="dropDown">
<ul>
<li>Test</li>
<li>Test-Dropdown
<ul>
<li>Drop down content</li>
<li>Drop down content</li>
<li>Drop down content</li>
</ul>
</li>
<li>Test</li>
</ul>
</div>
CSS: To active the dropdown do something like this.
.dropDown > ul > li:hover > ul {
display: block;
}
.dropDown > ul > li > ul {
display: none;
position: relative;
bottom: 0;
left: 0;
}
add anymore styles you would like it to have
My fiddle to help you get started
Here is a drop down menu, no javascript needed.
css
menu, menu ul.drop-menu {
padding:0;
margin: 0;}
menu li, menu ul.drop-menu li {
list-style-type: none;
display: inline-block;}
menu li a, menu li ul.drop-menu li a {
text-decoration: none;
color: #fff;
background-color:#000 ;
padding: 5px;
display:inline-block;}
menu li {
position: relative;}
/*drop menu*/
menu li ul.drop-menu {
display:none;
position: absolute;
top: 30px;
left: 0;
width: 100px;}
menu li:hover ul.drop-menu {
display:block;}
html
<ul id="menu">
<li>
Menu 1
<ul class="drop-menu">
<li>
Drop Menu 1
</li>
<li>
Drop Menu 2
</li>
<li>
Drop Menu 3
</li>
<li>
Drop Menu 4
</li>
</ul>
</li>
</li>
<li>Menu 2
<ul class="drop-menu">
<li>
Drop Menu 1
</li>
<li>
Drop Menu 2
</li>
<li>
Drop Menu 3
</li>
<li>
Drop Menu 4
</li>
</ul>
</li>
<li>
Menu 3
</li>
</ul>
Related
I'm a beginner in web developing, when I hover my mouse to the list of my menus the dropdown menu keeps on showing in every menu. What seems to be the problem?
I tried removing the so I can use "ul li ul li" directly in css but it doesn't work and also when I try ".site-header nav ul li:hover .sub-menu-about" there is no output but ".site-header nav ul:hover .sub-menu-about" I've got the same problem even when I use ".site-header ul:hover .sub-menu-about" still the same problem.
Here is my CSS code
.sub-menu-about{
display: none;
}
.site-header ul:hover .sub-menu-about {
display: block;
margin-top: 15px;
margin-left: -15px;
position: absolute;
}
.main-navigation ul:hover .sub-menu-about ul{
display: block;
margin: 10px;
}
and this is my html code
<div class="site-header__menu group">
<nav class="main-navigation">
<ul>
<li>Home</li>
<li>About</li>
<div class="sub-menu-about">
<ul>
<li><a href="#">History</li>
<li><a href="#">Vision</li>
<li><a href="#">Mission</li>
</ul>
</div>
<li>News</li>
<li>Events</li>
</ul>
</nav>
</div>
Once I hover on the about menu, a dropdown list of History, Mission, Vision will be shown. and when I hover on different menus there will be no dropdown menu will be shown
Error No. 1: The submenu should be located inside the <li> tag. Corrected
Error No. 2:
First, you hide the class .sub-menu-about through displays: none, and then you try to show not this class itself, but a list inside it. Corrected
Result
.sub-menu-about {
display: none;
}
.site-header ul:hover .sub-menu-about {
display: block;
margin-top: 15px;
margin-left: -15px;
position: absolute;
}
.main-navigation li:hover .sub-menu-about {
display: block;
margin: 10px;
}
<div class="site-header__menu group">
<nav class="main-navigation">
<ul>
<li>Home</li>
<li>About
<div class="sub-menu-about">
<ul>
<li><a href="#">History</li>
<li><a href="#">Vision</li>
<li><a href="#">Mission</li>
</ul>
</div>
</li>
<li>News</li>
<li>Events</li>
</ul>
</nav>
</div>
I have a problem. I can't crate my droppable menu.
https://probapro2.blogspot.com/
I work on Menu 1, but I don't know what to add to make the drop menus to move on right.
<link href='http://fonts.googleapis.com/css?family=Oswald:300,400' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300' rel='stylesheet' type='text/css' />
<div class="nav">
<ul class="menu" id="menu">
<li> home </li>
<li class=""> <a class="drop-ctg" href="#">category</a>
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1072; opacity: 0;">
<li> Category 1 </li>
<li> Category 2 </li>
<li> Category 3 </li>
<li> Category 4 </li>
</ul>
</li>
<li class="">
Menu 1
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1069; opacity: 0;">
<li class="dir">
Menu 2
<ul style="overflow: hidden; display: block; height: 0px; z-index: 1070; opacity: 0;">
<li style="margin-left:50px;"> Menu 3 </li>
<li> Menu 3 </li>
<li> Menu 3 </li>
</ul>
</li>
<li class=" "> Menu 2 </li>
<li> Menu 2 </li>
<li> Menu 2 </li>
</ul>
</li>
<li> Menu 2 </li>
<li> Menu 3 </li>
<li> Menu 4 </li>
<li> 404 Error Page </li>
</ul>
</div>
Here JS fiddle: https://jsfiddle.net/0ugodkb3/2
I want to make Menu 1 to have a droppable menu with menu 2 and on first menu 2, I want to show menu 3.
You can use for that css rule transform with translate value like this:
*{
margin:0;
padding:0;
outline:0;
}
.nav {
width:950px;
height:auto;
border-bottom:1px solid #eee;
margin:10px auto 5px;
display:inline-block;
}
.menu {
width:auto;
list-style:none;
font:$pagenavifont;
text-align:center;
margin:0 auto;
}
.menu a {
float:left;
color:#999;
text-decoration:none;
text-transform:uppercase;
width:auto;
line-height:36px;
padding:0 20px;
}
.menu a:hover,li.menuhover a{
color:#111;
}
.menu li {
position:relative;
float:left;
width:auto;
}
.menu li:last-child {
background:none;
}
.menu ul{
display:none;
position:absolute;
top:36px;
left:0;
background:#fbfbfb;
display:none;
list-style:none;
}
.menu ul li{
float:none;
border-top:1px solid #e3e3e3;
border-right:1px solid #e3e3e3;
border-left:1px solid #e3e3e3;
width:auto;
background:none;
}
.menu ul li:last-child {
border-bottom:1px solid #e3e3e3
}
.menu ul li a{
float:none;
display:block;
background:none;
line-height:36px;
min-width:137px;
width:auto;
text-align:left;
padding-left:10px;
color:#444;
}
.menu ul li a:hover{
background:#fdfdfd;
color:#777;
}
.menu > li > ul {
display: none;
}
.menu > li > ul > li > ul {
transform: translate(100%,0);
display: none;
margin-top: -37px;
}
.menu > li:hover > ul,
.menu > li > ul > li:hover > ul {
display: block;
}
<div class="nav">
<ul class="menu">
<li>
home
</li>
<li class="">
<a class="drop-ctg" href="#">category</a>
<ul>
<li>
Category 1
</li>
<li>
Category 2
</li>
<li>
Category 3
</li>
<li>
Category 4
</li>
</ul>
</li>
<li>
Menu 1
<ul>
<li class="dir">
Menu 2
<ul>
<li>
Menu 3
</li>
<li>
Menu 3
</li>
<li>
Menu 3
</li>
</ul>
</li>
<li>
Menu 2
</li>
<li>
Menu 2
</li>
<li>
Menu 2
</li>
</ul>
</li>
<li>
Menu 2
</li>
<li>
Menu 3
</li>
<li>
Menu 4
</li>
<li>
404 Error Page
</li>
</ul>
</div>
The main thing is to use > selector when defining the display rule for nested menus. This is all what I've added to your css code:
.menu > li > ul {
display: none;
}
/* Position for the 3rd level menu */
.menu > li > ul > li > ul {
transform: translate(100%,0);
display: none;
margin-top: -37px;
}
.menu > li:hover > ul,
.menu > li > ul > li:hover > ul {
display: block;
}
There are a few things that go into making a dropdown menu. It sounds like you're trying to make a dropdown menu that opens up nested menus.
Each pop-out menu will need to:
1) Know the position of the parent that is opening the menu to know where it should be appended.
2) Calculate where the nav should pop up based on where there user is on the browser/screen
You need to append the nav on the right of the menu header you want to open. I'm not sure what your restrictions are but there are vanilla js options:
https://gomakethings.com/how-to-insert-an-element-after-another-one-in-the-dom-with-vanilla-javascript/
that you can use, and also use a mix of position: relative; and position: fixed; to add your nested menus to the right of it's parent.
I would strongly urge you to consider if creating a custom, nested dropdown menu is the right option for you. There are many options out there that have been battle-tested through time. Normally these will also let you style the menu header, and also it's children.
Let me know if you have any more questions :)
got an html list working as a dropdown menu with CSS when you hover through a < li > element like "Products" in my example. But what I want is the same effect when hover through < h3 > like "Contact" from my example. Is it possible?
Here's the html:
<h3>Contact</h3>
<ul>
<li>Home</li>
<li>About</li>
<li>
Products ▾
<ul>
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
<li>Contact</li>
</ul>
And the CSS code:
ul li ul {
display: none;
}
ul li:hover ul{
display: block; /* display the dropdown */
}
Thank you very much in advance.
On hover you can only control the CSS of the element you hover over, or the CSS of elements within the element you hover over (one of its children).
So you can not make the ul change styles when you hover over the h3 because they 1) are not the same object and 2) do not have a parent-child relationship (they are siblings).
To show the menu when hovering over the h3, you can wrap both of them inside another object (div) and use this for the hover event. To distinguish between the two hovers you can add classnames to both the uls.
See this JSfiddle, or the code below:
<div class="container">
<h3>Contact</h3>
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>
Products ▾
<ul class="submenu">
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
.container ul{
display: none;
}
.container:hover ul.menu{
display: block;
}
ul li ul.submenu {
display: none;
}
ul li:hover ul{
display: block; /* display the dropdown */
}
In short - you should nest ul inside the h3
<h3>
Contact
<ul>
<li>Home</li>
<li>About</li>
<li>
Products ▾
<ul>
<li>Laptops</li>
<li>Monitors</li>
<li>Printers</li>
</ul>
</li>
<li>Contact</li>
</ul>
</h3>
And in your css:
ul li ul {
display: none;
}
ul li:hover ul{
display: block; /* display the dropdown */
}
h3 > ul {
display: none;
}
h3:hover > ul {
display: block;
}
Here's the demo: https://jsfiddle.net/mscehjLf/1/
Specifically on IE9 only, my navigation menu is sitting behind my iframe when viewing a PDF through that iFrame.
I have set up a jsfiddle to demonstrate:
http://jsfiddle.net/q6fmv/
Alternatively please see the bottom of this question for the code.
When viewed on IE9 if you hover over the navigation elements, the ones that have a sub nav you can see are hidden behind the iFrame.
I have tried setting the z-index of the nav menu to be higher than that of the iFrame but it didnt work.
How can I resolve this so the sub menu of the navigatino menu appears on top of the iframe?
HTML
<div id="navMenu">
<ul id="menu">
<li>
Menu 1
</li>
<li>Menu 2
<ul class="sub-menu">
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>Menu 3
</li>
<li>Menu 4
<ul class="sub-menu">
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>
Menu 5
</li>
</ul>
</div>
<br />
<div id="iframe">
<iframe name="myiFrame" width="100%" height="100%" title="My iFrame" id="myIframe" src="http://www.education.gov.yk.ca/pdf/pdf-test.pdf" frameBorder="0"/>
</div>
CSS
/*Initialize*/
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;
width: 100px;
}
ul#menu li:hover ul.sub-menu {
display:block;
}
Have also tried using PDFObject.js http://jsfiddle.net/q6fmv/10/. It didnt work
Have you tried the empty iframe technique ?
It was not working before because you need to add an empty iframe inside each submenu ul tag.
HTML
<div id="outer">
<div id="inner">
<div id="navMenu">
<ul id="menu">
<li>
Menu 1
</li>
<li>Menu 2
<ul class="sub-menu">
<iframe class="cover" src="about:blank"></iframe>
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>Menu 3
</li>
<li>Menu 4
<ul class="sub-menu">
<iframe class="cover" src="about:blank"></iframe>
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>
Menu 5
</li>
</ul>
</div>
CSS
#outer {
position: relative;
left:0;
top: 0;
width: 100%;
z-index: 3;
}
#inner{
background: red;
}
.cover {
position: absolute;
border: none;
top: 0;
left: 0;
width: 100%;
z-index: -2;
height:100%;
}
#pdf {
position: relative;
top:0;
z-index: 1;
}
ul#menu, ul#menu ul.sub-menu {
padding:0;
margin: 0;
z-index:3;
}
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;
width: 100px;
z-index:3;
}
ul#menu li:hover ul.sub-menu {
display:block;
position:absolute;
z-index:3;
}
EXAMPLE
http://jsfiddle.net/gDuCE/701/
I have used google docs code for embedding via iframe to the website.
I have added jsfiddle link which you can directly check in ie9.
JSFiddle code
JSFiddle fullscreen code - check this directly in ie9
If you are using google documents as iframe, then please do make sure that it is shared publicly.
<div id="navMenu">
<ul id="menu">
<li>
Menu 1
</li>
<li>Menu 2
<ul class="sub-menu">
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>Menu 3
</li>
<li>Menu 4
<ul class="sub-menu">
<li>
Sub Menu 1
</li>
<li>
Sub Menu 2
</li>
<li>
Sub Menu 3
</li>
<li>
Sub Menu 4
</li>
</ul>
</li>
<li>
Menu 5
</li>
</ul>
</div>
<br />
<div id="iframe">
<!--<iframe name="myiFrame" width="100%" height="100%" title="My iFrame" id="myIframe" src="http://www.education.gov.yk.ca/pdf/pdf-test.pdf" frameBorder="0"/>-->
<iframe src="https://docs.google.com/file/d/0ByF4RjDx3q6sMW9DWHR0MXNtN0k/preview" width="100%" height="100%"></iframe>
</div>
Regards D.
Try adding position and z-index to #menu or #navMenu as such
ul#menu {
position: relative;
z-index: 9999;
}
http://jsfiddle.net/q6fmv/7/
I don't have IE9 to check though
I need a single drop down menu that is displayed only on hover. From the drop down menu list, I need a further list on hover on one of the child items.
The keyword/ parent is Subjects.
On hover (on the word Subjects) it has to display:
Maths
English
Spanish
History
Science
Extra
Marks
On hover on the child Extra, it has to display 3 further items:
Arts
Sports
Community
I have tried both dropdown and dropup menus, but the child menu items (ie Arts, Sports and Community) are displayed even as I hover on the parent Subjects. They have to appear only on hover on Extra.
I'm CSS challenged, tried my best from drop down scripts downloaded online. But none seem to address this situation.
Here's the HTML for the menu. Not sure if I'm doing it right.
<nav id="subjectsNav">
<ul>
<li class="last">SUBJECTS
<ul>
<li>Maths
</li>
<li>English
</li>
<li>Spanidsh
</li>
<li>History
</li>
<li>Science
</li>
<li>EXTRA
</li>
<ul id="extraNav">
<li>Arts
</li>
<li>Sports
</li>
<li>Community
</li>
</ul>
<li>Marks
</li>
</ul>
</li>
</ul>
</nav>
Need help with the HTML and CSS for the above. Yours answers are much appreciated. Many thanks for taking your time.
extraNav submenu must be inside of parent list item:
<ul id="subjectsNav">
<li>SUBJECTS
<ul>
<li>Maths
</li>
<li>English
</li>
<li>Spanidsh
</li>
<li>History
</li>
<li>Science
</li>
<li>EXTRA
<ul>
<li>Arts
</li>
<li>Sports
</li>
<li>Community
</li>
</ul>
</li>
<li>Marks
</li>
</ul>
</li>
</ul>
CSS:
/* Main */
#subjectsNav {
list-style: none;
}
#subjectsNav li {
width: 70px;
display: block;
float: left;
position: relative;
}
#subjectsNav li:hover > ul {
display: block;
}
/* Sub-menu */
#subjectsNav ul {
list-style: none;
left: 0;
margin: 0;
padding: 0;
display: none;
position: absolute;
z-index: 99999;
}
#subjectsNav ul li {
float: none;
display: block;
}
#subjectsNav ul ul {
top: 0;
left: 70px;
}
Demo:
http://jsfiddle.net/Bc2sv/