CSS active pseudo-class 改变状态吞噬onclick事件
CSS active pseudo-class changing state swallows up onclick event
我正在改编一个 here 的示例,使其更像一个 "real" 菜单,因为它应该在用户点击时折叠。
我更喜欢这样一个事实,即菜单的所有视觉方面都在 css 中处理,而 javascript 仅用于处理用户 [=65] 时所需的操作=] 是一个选项。我觉得这是最适合我的特定应用程序的方法。
但是,当菜单被收起时,我发现分配给每个 link 的 onclick 事件被删除(或忽略)。
我发布了 2 个版本,一个在用户 select 一个选项时触发了所需的 onclick 事件,另一个很好地收起了菜单,但也吞噬了点击事件。我正在寻求一种将 2 个结果合并到一个工作菜单中的解决方案,它也满足了点击后自动收起的要求。
EDIT 刚刚注意到我注释掉了一些额外的代码(在找出 css 唯一解决方案之前的早期尝试。我正在调用 mouseleave,但没有效果。
两个版本之间的唯一区别是添加了一个 CSS 子句:
#menuwrapper ul:active{
display:none;
}
版本 "works",但不会折叠菜单
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').click(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
/*
#menuwrapper ul:active{
display:none;
}
*/
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>
折叠菜单但不触发 onclick 的版本
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').click(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
#menuwrapper ul:active{
display:none;
}
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>
您可以尝试使用 mousedown 而不是 click
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').mousedown(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
#menuwrapper ul:active{
display:none;
}
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>
我正在改编一个 here 的示例,使其更像一个 "real" 菜单,因为它应该在用户点击时折叠。
我更喜欢这样一个事实,即菜单的所有视觉方面都在 css 中处理,而 javascript 仅用于处理用户 [=65] 时所需的操作=] 是一个选项。我觉得这是最适合我的特定应用程序的方法。
但是,当菜单被收起时,我发现分配给每个 link 的 onclick 事件被删除(或忽略)。
我发布了 2 个版本,一个在用户 select 一个选项时触发了所需的 onclick 事件,另一个很好地收起了菜单,但也吞噬了点击事件。我正在寻求一种将 2 个结果合并到一个工作菜单中的解决方案,它也满足了点击后自动收起的要求。
EDIT 刚刚注意到我注释掉了一些额外的代码(在找出 css 唯一解决方案之前的早期尝试。我正在调用 mouseleave,但没有效果。
两个版本之间的唯一区别是添加了一个 CSS 子句:
#menuwrapper ul:active{
display:none;
}
版本 "works",但不会折叠菜单
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').click(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
/*
#menuwrapper ul:active{
display:none;
}
*/
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>
折叠菜单但不触发 onclick 的版本
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').click(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
#menuwrapper ul:active{
display:none;
}
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>
您可以尝试使用 mousedown 而不是 click
var display = document.getElementById("display");
$(document).ready(function() {
$('li.menu_clickable').mousedown(function() {
if (this.children.length === 1) {
//$(this).trigger('mouseleave');
display.innerHTML = 'you clicked ' + this.innerHTML;
}
});
});
/* Define the body style */
body {
font-family: Arial;
font-size: 12px;
}
#maindiv {
position: absolute;
left: 200px;
top: 0px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul,
#menuwrapper ul li {
margin: 0;
padding: 0;
list-style: none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li {
background-color: #7f95db;
border-bottom: solid 1px white;
width: 150px;
cursor: pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover {
background-color: #6679e9;
position: relative;
z-index: 100;
}
/* We apply the link style */
#menuwrapper ul li a {
padding: 5px 15px;
color: #ffffff;
display: inline-block;
text-decoration: none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul {
position: absolute;
display: none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul {
left: 150px;
top: 0px;
display: block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li {
background-color: #cae25a;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover {
background-color: #b1b536;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a {
color: #454444;
display: inline-block;
width: 120px;
}
/**** THIRD LEVEL MENU ****/
/* We need to hide the 3rd menu, when hovering the first level menu */
#menuwrapper ul li:hover ul li ul {
position: absolute;
display: none;
}
/* We show the third level menu only when they hover the second level menu parent */
#menuwrapper ul li:hover ul li:hover ul {
display: block;
left: 150px;
top: 0;
}
/* We change the background color for the level 3 submenu*/
#menuwrapper ul li:hover ul li:hover ul li {
background: #86d3fa;
}
/* We change the background color for the level 3 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover ul li:hover {
background: #358ebc;
}
/* We change the level 3 link color */
#menuwrapper ul li:hover ul li:hover ul li a {
color: #ffffff;
}
/* Hide the menu when a link is clicked on */
#menuwrapper ul:active{
display:none;
}
/* Clear float */
.clear {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="menuwrapper">
<ul>
<li class="menu_clickable"><a href="#">Home</a>
</li>
<li class="menu_clickable"><a href="#">Products</a>
<ul>
<li class="menu_clickable"><a href="#">Product 1</a>
<ul>
<li class="menu_clickable"><a href="#">Sub Product 1</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Sub Product 3</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Product 2</a>
</li>
<li class="menu_clickable"><a href="#">Product 3</a>
</li>
</ul>
</li>
<li><a href="#">About Us</a>
<ul>
<li class="menu_clickable"><a href="#">Faqs</a>
</li>
<li class="menu_clickable"><a href="#">Contact Us</a>
</li>
<li class="menu_clickable"><a href="#">Where are we?</a>
</li>
</ul>
</li>
<li class="menu_clickable"><a href="#">Help</a>
</ul>
</div>
<div id="maindiv">
<div>
<label id="display">click an option</label>
</div>
<div>
<button onclick="alert('hey!');">
some button
</button>under the menu
</div>
<div>
<input value="some input box">under the menu
</div>
</div>