Below is my snippet. First, I have two different link which triggered a drop down sub menu when hovered. Now the problem is, If you hover on the "First menu" (this is a fixed position), its drop down sub menu does not overlap like the second drop down sub menu from the second menu, it contains itself to its parent which seem's ugly, any ideas, help, clues, suggestions, recommendations to fix this please?
a{text-decoration:none;color:#000000;}
ul,li{list-style:none;padding:0px;}
#menu{overflow-y:auto;overflow-x:hidden;max-height:50px;background:#ededed;color:#ffffff !important;padding:15px;position:fixed;width:300px}
.sub_menu{
position:absolute;
z-index:99999999999;
background:red;
padding:15px;
color:#000000;
display:none;
}
.d_menu a:hover + .sub_menu{display:block !important;}
#menu2{overflow-y:auto;overflow-x:hidden;max-height:50px;background:#ededed;color:#ffffff !important;padding:15px;margin-top:50px;}
<div id="menu">
<ul class="d_menu">
<li>
This is first menu, this has a fixed position
<ul class="sub_menu">
<li>sub menu 1</li>
<li>sub menu 2</li>
<li>sub menu 3</li>
<li>sub menu 4</li>
<li>sub menu 5</li>
<li>sub menu 6</li>
<li>sub menu 7</li>
<li>sub menu 8</li>
<li>sub menu 9</li>
<li>sub menu 10</li>
</ul>
</li>
<li>menu 2</li>
<li>menu 3</li>
<li>menu 4</li>
<li>menu 5</li>
</ul>
</div>
<br>
<br>
<div id="menu2">
<ul class="d_menu">
<li>
This is second menu, this has a static position
<ul class="sub_menu">
<li>sub menu 1</li>
<li>sub menu 2</li>
<li>sub menu 3</li>
<li>sub menu 4</li>
<li>sub menu 5</li>
<li>sub menu 6</li>
<li>sub menu 7</li>
<li>sub menu 8</li>
<li>sub menu 9</li>
<li>sub menu 10</li>
</ul>
</li>
</ul>
</div>
You just have to remove overflow-y and overflow-x and it will work :
a{text-decoration:none;color:#000000;}
ul,li{list-style:none;padding:0px;}
#menu{max-height:50px;background:#ededed;color:#ffffff !important;padding:15px;position:fixed;width:300px}
.sub_menu{
position:absolute;
z-index:99999999999;
background:red;
padding:15px;
color:#000000;
display:none;
}
.d_menu a:hover + .sub_menu{display:block !important;}
#menu2{overflow-y:auto;overflow-x:hidden;max-height:50px;background:#ededed;color:#ffffff !important;padding:15px;margin-top:50px;}
<div id="menu">
<ul class="d_menu">
<li>
This is first menu, this has a fixed position
<ul class="sub_menu">
<li>sub menu 1</li>
<li>sub menu 2</li>
<li>sub menu 3</li>
<li>sub menu 4</li>
<li>sub menu 5</li>
<li>sub menu 6</li>
<li>sub menu 7</li>
<li>sub menu 8</li>
<li>sub menu 9</li>
<li>sub menu 10</li>
</ul>
</li>
</ul>
</div>
<br>
<br>
<div id="menu2">
<ul class="d_menu">
<li>
This is second menu, this has a static position
<ul class="sub_menu">
<li>sub menu 1</li>
<li>sub menu 2</li>
<li>sub menu 3</li>
<li>sub menu 4</li>
<li>sub menu 5</li>
<li>sub menu 6</li>
<li>sub menu 7</li>
<li>sub menu 8</li>
<li>sub menu 9</li>
<li>sub menu 10</li>
</ul>
</li>
</ul>
</div>
Related
I'm trying to build a mega menu with flexbox. The only issue I have left figuring out how I can "Redskap & tillbehör" into 3 columns so it fills the column before and after it. Right now it's just cutting out some of the items.
http://dataring.se/dev/wiggs3/
Here is how I want it to look
I could achieve 4 column menu layout with very basic css that solves your use case. Additional styling as per your design guidelines you can include to this
body {
margin: 0;
}
ul {
padding: 0;
list-style: none;
}
.menu-items {
columns: 4;
display: none;
}
.menu > li:hover .menu-items {
display: block;
}
<ul class="menu">
<li>
Main Menu
<ul class="menu-items">
<li>
Menu Item Header
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>
Menu Item Header
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>
Menu Item Header
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>
Menu Item Header
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
<li>
Menu Item Header
<ul>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
<li>Sub menu item</li>
</ul>
</li>
</ul>
</li>
</ul>
I am creating a mobile menu as dropdown list items as follows,
jQuery('#menu-main-menu > .is-dropdown-submenu-parent a').click(function() {
$(this).siblings('ul').slideToggle(500);
jQuery(this)
.closest(".is-dropdown-submenu-parent")
.siblings()
.find(".sub-menu")
.slideUp();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="main-menu-mobile" class="menu-list navbar-collapse collapse clearfix">
<ul id="menu-main-menu" class="navigation clearfix" style="display:flex; flex-direction: column">
<li data-toggle="collapse" class="dropdown is-dropdown-submenu-parent collapsed">
menu 1
<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 data-toggle="collapse" class="dropdown is-dropdown-submenu-parent collapsed">
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>
</ul>
</div>
The problem is when I click into the main menu for opening, it opens outside the frame of the menu (it gets outside the container) explain more: when I click on the menu1 the items of it appear above the menu2. Where it suppose to shift menu2 down and list the items bellow menu1.
I did not get where is the error & I have searched & seen all menus made as I did !!
Try this small change
I have commented slideUp() line in the .js.
I think it works as you want.
jQuery('#menu-main-menu > .is-dropdown-submenu-parent a').click(function() {
$(this).siblings('ul').slideToggle(500);
jQuery(this)
.closest(".is-dropdown-submenu-parent")
.siblings()
.find(".sub-menu")
//.slideUp(); // commented this line
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="main-menu-mobile" class="menu-list navbar-collapse collapse clearfix">
<ul id="menu-main-menu" class="navigation clearfix" style="display:flex; flex-direction: column">
<li data-toggle="collapse" class="dropdown is-dropdown-submenu-parent collapsed">
menu 1
<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 data-toggle="collapse" class="dropdown is-dropdown-submenu-parent collapsed">
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>
</ul>
</div>
I just want the text to be clickable not the entire list item block.
<a class="menu_head">Hello</a>
<ul class="menu_body">
<li>Sub-menu 1</li>
<li>Sub-menu 2</li>
<li>Sub-menu 3</li>
<li>Sub-menu 4</li>
<li>Sub-menu 5</li>
<li>Sub-menu 6</li>
<li>Sub-menu 7</li>
</ul>
</body>
</html>
add this to your css
a {display:inline-block;}
I want to make a two columns drop down menu like this.
Main Menu 1 | Main Menu 2 | Main Menu 3
Sub Menu 1 | Sub Menu 5
Sub Menu 2 | Sub Menu 6
Sub Menu 3 | Sub Menu 7
Sub Menu 4
Here is my code.
<style>
ul{
list-style:none;
}
li{
float:left;
}
li li {
width:50%;
}
</style>
<ul>
<li>Main Menu 1
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4</li>
<li>Sub Menu 5</li>
<li>Sub Menu 6</li>
<li>Sub Menu 7</li>
</ul>
</li>
<li>Main Menu 2</li>
<li><a href="#" target="_self" >Main Menu 1</a></li>
</ul>
But if I use float left, it becomes this.
Main Menu 1 | Main Menu 2 | Main Menu 3
Sub Menu 1 | Sub Menu 2
Sub Menu 3 | Sub Menu 4
Sub Menu 5 | Sub Menu 6
Sub Menu 7
How can I make it by CSS or Query? Any ideas? Thanks!!
If you need to stick to just HTML, you can either reorder your list items to fall in alternating order:
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 5</li>
<li>Sub Menu 2</li>
<li>Sub Menu 6</li>
<li>Sub Menu 3</li>
<li>Sub Menu 7</li>
<li>Sub Menu 4</li>
</ul>
Which isn't great, but works.
Or, you can separate the list into two lists (also not the best solution).
<ul class="col1">
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 4</li>
</ul>
<ul class="col2">
<li>Sub Menu 5</li>
<li>Sub Menu 6</li>
<li>Sub Menu 7</li>
</ul>
If your content is generated elsewhere, or you're unable to adjust your lists for some reason, A List Apart has a good article on this: http://alistapart.com/article/multicolumnlists
The answer: google it. "CSS multi-level navigation" brought me 29 800 000 results.
http://www.htmldog.com/articles/suckerfish/dropdowns/
http://alistapart.com/article/dropdowns
http://speckyboy.com/2013/01/30/more-responsive-navigation-solutions/
http://www.noupe.com/css/multilevel-drop-down-navigation-menus-examples-and-tutorials.html
http://woork.blogspot.be/2009/09/how-to-implement-perfect-multi-level.html
http://geek.ryanhellyer.net/products/suckerfish_css/
And tons of others.
I have a very good menu right here:
http://jsfiddle.net/y9jbQ/
<ul id="nav">
<li>Menu 1
<ul class="nav first">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4
<ul class="nav">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
</li>
</ul>
</li>
<li>Menu 2</li>
<li>Menu 3</li>
<li>Menu 4</li>
</ul>
the problem is now, let's say I want a right-arrow image, aligned to right in case when there's an other sub menu. Putting inside isn't healthy thing. I don't want to create anything to copy 's behaviour. So,
<li><div float left><div float right></li>
is not a good way.
Use a CSS Child Selector:
ul.root > li > a { /* css declarations */ }
This will only apply the rules to the direct descendants of the root ul element.
Illustration:
<ul class="root">
<li>
<!-- MATCH -->
</li>
<li>
<!-- MATCH -->
<ul>
<li>
<!-- NO MATCH -->
</li>
</ul>
</li>
</ul>