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 :)
Related
I need to align dropdown menu along the length of the page. I have a menu :
<ul class="nav navbar-nav menu">
<li>About the company
<img src="images/arr1.png" ></img>
<ul>
<li class="first_li">Mission</li>
<li>History</li>
<li>Vacancy</li>
<li>Best Experts</li>
</ul>
</li>
</ul>
Then I have some css styles to make this dropdown menu to be align in as I thougth right manner.But it doesn't work correctly.
.menu li{
list-style: none;
float: left;
line-height:84px;
}
.menu li:hover > ul {
display: block;
background-color: rgb(231,231,231);
position:absolute;
top:84px;
left : 0px;
width: 100%;
text-align:center;
padding:0;
z-index:1;
}
.menu .language:hover > ul {
display:block;
width:84px;
line-height:30px;
}
Part of the problem looks like you have most of your list style in the 'hover' part. Try putting that into the general menu style.
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 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>
I'm trying to create a mega drop down menu just like the one from the following link : http://i48.tinypic.com/2ln97ip.png
I have created this fiddle but the things aren't going well because of positioning and border of second ul is not ok :(
http://jsfiddle.net/H8FVE/16/
<ul id="firstUl">
<li><a>mainSimple</a></li>
<li>
<a>MainMenu</a>
<ul id="secondUl">
<li>
<a>SecondLevel1</a>
<ul id="lastLevel">
<li>
<a>LastLevelX</a>
</li>
<li>
<a>LastLevelY</a>
</li>
</ul>
</li>
<li>
<a>SecondLevel2</a>
<ul id="lastLevel">
<li>
<a>LastLevel</a>
</li>
<li>
<a>LastLevel</a>
</li>
<li>
<a>LastLevel</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
#firstUl{height:42px; position:relative; background:#ccc;}
#firstUl li{ float:left; border:1px solid #fff; padding:10px; border:1px solid red;}
#secondUl{display:none; background:#fafafa; }
#secondUl li{
float:left;
display:block;
border:1px solid #eaeaea;
}
#lastLevel{
display:none;
}
#firstUl li:hover> #secondUl{
border:1px solid red;
display:block;
position:absolute;
top:100%;
}
#firstUl li #secondUl li:hover> #lastLevel{
display:block;
position:absolute;
top:100%;
left:0;
}
#firstUl li #secondUl li #lastLevel li{
float:none;
}
Can someone help me with this pls.
Try setting the #secondUl li to position:relative so that the child's (UL) position depends on it:
#secondUl li {
...
position: relative;
}
I am trying to create a vertical menu with fly outs .That is a vertical menu with sub-menus.What is wrong with the following code?
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
#navmenu ul ul li a {
border:1px solid #888888; border-bottom: none; font-size:12pt; line-height: 1.6em; color:#303030; background-color:#a5a5a5; background-image:none;
}
#navmenu {
width: 150px; /* set width of menu */
}
#navmenu ul {
list-style-type:none; margin:0px; padding:0px;
}
#navmenu a {
text-decoration:none; border: 1px solid #303030; width:170px; display:block; text-align:center; font-size:14pt; line-height:2em; background:url(Button_top.gif) repeat-x left; font-family:Arial, Helvetica, sans-serif; color:white;
}
#navmenu a:hover {
color: #a00;
/* red text color on hover */
background: #fff;
/* white bgcolor on hover */
}
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
#navmenu ul ul {
position: absolute; top: 0; left: 100%;
/* to position them to the right of their containing block */
width: 100%;
/* width is based on the containing block */
}
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
#navmenu ul ul {
display: none;
}
#navmenu ul li:hover ul {
display:block;
}
</style>
</head>
<body>
<div id="navmenu">
<ul>
<li>
Home
</li>
<li>
Blog
</li>
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
<li>
Websites
</li>
<ul>
<li>
Websites 1
</li>
<li>
Websites 2
</li>
</ul>
<li>
Photos
</li>
</ul>
</div>
</body>
</html>
http://jsfiddle.net/9bHkj/1/
You might have to revisit how you are constructing the menu. For instance:
<li>
Blog
</li>
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
is supposed to be a Blog menu with two sub menus Blog 1 and Blog 2. But then <ul> for the sub menu is supposed to be within the <li> of the menu and not separately:
<li>
Blog
<!-- The <li> does not end here -->
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
</li> <!-- end tag for the blog <li>, now enclosing the submenu also -->
Once you do this, for the other submenus as well, you have the flying sub menus. You can now work out the location, colors etc.
you wrote this twice:
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
Your nested lists ul are not contained by li elements. So this will not work either:
#navmenu ul li:hover ul {
display:block;
}
nesting your ul in li elements may solve your problem.