Check live- http://uposonghar.com/testsite/
When i add more items to the menus - the menu container does not expand and items get outside the menu.
Screenshot-
Code-
<LI id=navPreretire><A title="Pre Retirement Procedures" href="http://pencproc/" target=_blank><SPAN class=singleLine>Pre Retirement Procedures</SPAN> </A>
<!--Mega menu drop-down part1, the div have to stay like that-->
<div class="dropdown">
<!--until here-->
<Ul>
<div class="dropdown_3rd_lvl1"><li >Plan Benifit Payment Procedures
<ul>
<li >Communications</li>
<li >Manage Payments</li>
<li >Manage Pension Benefits</li>
<li >Reports</li>
</UL></li></div>
<div class="dropdown_3rd_lvl2"><li >Pension Services Procedures
<ul>
<li >Communications</li>
<li >Manage Group Benefits</li>
<li >Manage Payments</li>
<li >Manage Pension Benefits</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
<li >Reports</li>
</UL></li></div>
</ul>
<!--Menu ends-->
</div>
<!--Menu ends-->
</LI>
CSS-
.dropdown{
display: none;
BACKGROUND-COLOR: #886d53;
clear: both;
}
.dropdown>ul>li{
clear: both;
float: left;
}
#menu li:hover .dropdown{
position: absolute;
display: block;
height:100%;
min-width: 430px;
margin: 38px auto;
padding-top: 5px;
}
.dropdown ul li{
clear: both;
}
#menu .dropdown ul li:hover{
clear: both;
}
Remove unnecessary height, position:absolute.
#menu li:hover .dropdown {
/*height: 200px;*/
}
#menu ul ul {
height: auto;
}
.dropdown_3rd_lvl1 {
/*position: absolute;*/
/*left: 0*/
/*margin-left: -30px;*/
float: left;
}
.dropdown_3rd_lvl2 {
/*position: absolute;*/
/*margin-left: 170px;*/
float: left;
}
The problem is, at least partly, due to your #menu ul, which applies a height: 38px to the bar, but also gets applied to the ul descendant a few layers deeper.
The entire menu bar seems a bit too complex for what you are trying to achieve, and could be done in a much simpler way.
Related
We all have hard times with positioning absolute divs :S
In my case its horizontal sub-menus with this css:
ul.children{
display:none;
position:absolute;
}
ul.children li{
position:relative;
height:60px;
float:none;
}
li.page_item_has_children:hover > ul.children{
display:inline;
}
As you can see on the picture whole submenu moves to the left for 50% of the parents width...
I tried everything and created just a bigger mess xD
So if anyone can help me out with this I will be very thankful :)
HTML:
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
I can't change html cause its wordpress theme :S
Try something like this:
ul {
list-style-type: none;
padding: 0;
}
.page_item_has_children {
position: relative;
}
ul.children {
display: none;
position: absolute;
top: 100%;
left: 0;
padding: 0;
min-width: 200px; /* or whatever makes sense */
}
ul.children li {
height: 60px;
}
.page_item_has_children:hover > ul.children {
display: block;
}
The important piece here is to make sure the 'page_item_has_children' element is relatively positioned and that the child 'ul' is absolutely positioned.
JS Fiddle
Update
ul.children {
display: none;
}
ul.children li {
position: relative;
height: 60px;
float: none;
}
li.page_item_has_children:hover > ul.children {
display: inline;
}
li {
float: left;
list-style-type: none;
width: 5em;
}
<ul>
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
<li class="page_item page-item-2 page_item_has_children">
More info
<ul class='children'>
<li class="page_item page-item-39">
Item 1</li>
<li class="page_item page-item-41">
Item 2</li>
<li class="page_item page-item-41">
Item 3</li>
</ul>
</li>
</ul>
So, I've got a sub menu ul item, which I need to expand to the auto width of the widest child li, without specifying actual width. As of right now, child ul is taking the width of .mainlink and text inside li items starts collapsing. I need it to be in one line and go beyond .mainlink width if necessary.
I've tried all the possible displays, but can't get it to work.
.mainnav {
display: table;
table-layout: fixed;
}
ul.mainnav li {
display: table-cell;
}
.subnav {
position: absolute;
top: 40px;
}
.menuitem {
position: relative;
display: block;
}
<ul class="mainnav">
<li class="mainlink">Link 11
</li>
<li class="mainlink">
Link 12
<ul class="subnav">
<li class="menuitem">link 1
</li>
<li class="menuitem">link 2
</li>
</ul>
</li>
</ul>
reset padding on .subnav because ul has padding by default
UPDATE (based on OP updated question)
use display:inline-block in .mainnav > li
.mainnav {
background:lightyellow;
position:relative
}
ul.mainnav > li {
display: inline-block;
background:lightblue;
}
.subnav {
position: absolute;
top: 40px;
padding: 0;
border: 5px solid green
}
.menuitem {
position: relative;
display: block;
background: red
}
<ul class="mainnav">
<li class="mainlink">Link 11</li>
<li class="mainlink">
Link 12
<ul class="subnav">
<li class="menuitem">link 1
</li>
<li class="menuitem">link 2 long text
</li>
</ul>
</li>
</ul>
We all have hard times with positioning absolute divs :S
In my case its horizontal sub-menus with this css:
ul.children{
display:none;
position:absolute;
}
ul.children li{
position:relative;
height:60px;
float:none;
}
li.page_item_has_children:hover > ul.children{
display:inline;
}
As you can see on the picture whole submenu moves to the left for 50% of the parents width...
I tried everything and created just a bigger mess xD
So if anyone can help me out with this I will be very thankful :)
HTML:
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
I can't change html cause its wordpress theme :S
Try something like this:
ul {
list-style-type: none;
padding: 0;
}
.page_item_has_children {
position: relative;
}
ul.children {
display: none;
position: absolute;
top: 100%;
left: 0;
padding: 0;
min-width: 200px; /* or whatever makes sense */
}
ul.children li {
height: 60px;
}
.page_item_has_children:hover > ul.children {
display: block;
}
The important piece here is to make sure the 'page_item_has_children' element is relatively positioned and that the child 'ul' is absolutely positioned.
JS Fiddle
Update
ul.children {
display: none;
}
ul.children li {
position: relative;
height: 60px;
float: none;
}
li.page_item_has_children:hover > ul.children {
display: inline;
}
li {
float: left;
list-style-type: none;
width: 5em;
}
<ul>
<li class="page_item page-item-2 page_item_has_children">
About
<ul class='children'>
<li class="page_item page-item-39">
About</li>
<li class="page_item page-item-41">
Contact us</li>
</ul>
</li>
<li class="page_item page-item-2 page_item_has_children">
More info
<ul class='children'>
<li class="page_item page-item-39">
Item 1</li>
<li class="page_item page-item-41">
Item 2</li>
<li class="page_item page-item-41">
Item 3</li>
</ul>
</li>
</ul>
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
I'm using a CSS dropdown menu that has CSS basically like this:
ul.dropdown,
ul.dropdown li,
ul.dropdown ul {
list-style: none;
margin: 0;
padding: 0;
}
ul.dropdown {
position: relative;
z-index: 597;
float: left;
}
ul.dropdown li {
float: left;
line-height: 1.3em;
vertical-align: middle;
zoom: 1;
}
ul.dropdown li.hover,
ul.dropdown li:hover {
position: relative;
z-index: 599;
cursor: default;
}
ul.dropdown ul {
visibility: hidden;
position: absolute;
top: 100%;
left: 0;
z-index: 598;
width: 100%;
}
ul.dropdown ul li {
float: none;
}
ul.dropdown ul ul {
top: 1px;
left: 99%;
}
ul.dropdown li:hover > ul {
visibility: visible;
}
My markup looks like this:
<div class="navcontainer" style="width: 100%;">
<ul id='saas-nav' class='dropdown'>
<li class='menu www'><a href='/saas/clients'>Surveys</a></li>
<li class='menu dir'><a href='#'>Preferences</a>
<ul>
<li class='menu flex'><a href='/admin/flex_module/saas_static/swf/Preferences.swf'>My Login</a></li>
<li class='menu www'><a href='/admin/my_clients/'>My Clients</a></li>
<li class='menu www'><a href='/admin/my_projects/'>My Projects</a></li>
</ul>
</li>
<li class='menu www'><a href='/admin/users'>Users</a></li>
</ul>
</div>
<!-- a small amount of content -->
<div style="width: 100%; padding-top: 4px;">
<ul id='survey-menu' class='dropdown'>
<li class='menu dir'><a href='#'>Survey</a>
<ul>
<li class='menu www'><a href='/saas/survey/useful_info/674'>Information</a></li>
<li class='menu www'><a href='/saas/survey/674/notes'>Notes</a></li>
<li class='menu www'><a href='/documents/674/'>Documents</a></li>
</ul>
</li>
<!-- ... -->
</ul>
What happens in this case is that the top menu's (the one in the 'navcontainer' div) dropdown items are covered by the navbar of the lower menu item. I believe that this is due to the z-index of the dropdown classes.
How can I re-style the page so that my dropdowns overlap properly? I want the top dropdown to always cover the bottom one, if it can, but I want to re-use as much of the styling as possible.
After a bit of tinkering, I think I have a solution. Check this out:
http://jsfiddle.net/hpvgH/6/
There is a bit of DOM changes and also styles. Here is the code:
<div class="navcontainer" style="width: 100%;">
<ul id='saas-nav' class='dropdown'>
<li class='menu www'><a href='/saas/clients'>Surveys</a></li>
<li class='menu dir'><a href='#'>Preferences</a>
<ul>
<li class='menu flex'><a href='/admin/flex_module/saas_static/swf/Preferences.swf'>My Login</a></li>
<li class='menu www'><a href='/admin/my_clients/'>My Clients</a></li>
<li class='menu www'><a href='/admin/my_projects/'>My Projects</a></li>
</ul>
</li>
<li class='menu www'><a href='/admin/users'>Users</a></li>
</ul>
</div>
<!-- a small amount of content -->
<div class="navcontainer" style="width: 100%; padding-top: 4px;">
<ul id='survey-menu' class='dropdown'>
<li class='menu dir'><a href='#'>Survey</a>
<ul>
<li class='menu www'><a href='/saas/survey/useful_info/674'>Information</a></li>
<li class='menu www'><a href='/saas/survey/674/notes'>Notes</a></li>
<li class='menu www'><a href='/documents/674/'>Documents</a></li>
</ul>
</li>
<!-- ... -->
</ul>
</div>
*{margin: 0; padding: 0;}
.navcontainer{clear: both;}
ul.dropdown,
ul.dropdown ul {
list-style: none;
z-index: 10;
}
ul.dropdown li {
float: left;
position: relative;
padding: 0 3px;
line-height: 1.3em;
vertical-align: middle;
zoom: 1;
}
ul.dropdown ul {
display: none;
position: absolute;
top: 10px;
left: 99%;
background-color: red;
}
ul.dropdown li:hover ul{
display: block;
}