Post by RockHard on Jul 26, 2016 14:54:46 GMT -5
I was looking for a dropdown that would open some content on my page by clicking rather than hovering on a button then close the same way & came up with a nice code & modified it a bit for appearance. I couldn't use it however 'cuz some of the content I wanted to have within the dropdown was also clickable that would close the window but if you don't have that issue this would work great & just about any content can be put inside the dropdown, tables, images, etc. This will open & close from the button but will also close clicking outside the dropdown. Nothing will happen clicking inside the dropdown & unlike most dropdowns, you can have inline content with the button. So here's what the code looks like. Play with the css to change the appearance as you see fit & if elements of your page bleed thru the dropdown, just raise the z index of the css menu content section & here's a sample image of this codes appearance.
<!DOCTYPE HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<style type="text/css">
body {background:#111}
.onclick-menu {
position: relative;
display: inline-block;width:25%
}
.onclick-menu:before {
background:#000;
box-shadow: inset 0px 0px 3px 3px #1a31ff, 0 0 0 2px #000;
border-radius:4px;
padding:13px;
font-family:arial;
font-size:16px;
color:#ffd500;
content: "click to show content";
}
.onclick-menu:focus { pointer-events: none }
.onclick-menu:focus .onclick-menu-content {
opacity: 1;
visibility: visible;
pointer-events: auto;
}
.onclick-menu-content {
margin-top:17px;
position: absolute;
background-color: #000;
border-radius:4px;
box-shadow: inset 0px 0px 3px 3px #1a31ff, 0 0 0 2px #000;
padding: 11px;
font-family:arial;font-size:16px;
text-align:center;
color:#ffd500;
font-weight:normal;
z-index: 1;
opacity: 0;
visibility: hidden;
}
</style>
<body>
<br><br>
<span tabindex="0" class="onclick-menu">
<div class="onclick-menu-content">
<p>This is what you'll get. Click outside the dropdown or the button again to close. It won't close inside the dropdown.</p>
</span>
</div>
</body>