How to make a pure css based dropdown menu?
see this is pure css bases dropdown menu:-
HTML
<ul id="menu">
<li><a href="">Home</a></li>
<li><a href="">About Us</a>
<ul>
<li><a href="">The Team</a></li>
<li><a href="">History</a></li>
<li><a href="">Vision</a></li>
</ul>
</li>
<li><a href="">Products</a>
<ul>
<li><a href="">Cozy Couch</a></li>
<li><a href="">Great Table</a></li>
<li><a href="">Small Chair</a></li>
<li><a href="">Shiny Shelf</a></li>
<li><a href="">Invisible Nothing</a></li>
</ul>
</li>
<li><a href="">Contact</a>
<ul>
<li><a href="">Online</a></li>
<li><a href="">Right Here</a></li>
<li><a href="">Somewhere Else</a></li>
</ul>
</li>
</ul>
CSS
ul
{
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li
{
display: block;
position: relative;
float: left;
}
li ul
{
display: none;
}
ul li a
{
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover
{
background: #617F8A;
}
li:hover ul
{
display: block;
position: absolute;
}
li:hover li
{
float: none;
font-size: 11px;
}
li:hover a
{
background: #617F8A;
}
li:hover li a:hover
{
background: #95A9B1;
}
see the demo:- http://jsfiddle.net/XPE3w/7/
Pure HTML and CSS toggleable drop-down menu
So what I've done on JS fiddle seems to work. I have done styling and mechanism. Hope it can help someone. It's pretty useful for the mobile (so they can quickly go through all pages without having to load Javascript or go on a page to leave it directly for a sub page, where they really want to go to.)
my code is entirely on JS Fiddle, no rights or anything is required to use, it's free, take it.
Pure CSS clickable dropdown?
Here you are using a hidden checkbox, and showing the menu when it is "checked".
/*hide the inputs/checkmarks and submenu*/input, ul.submenu { display: none;}
/*position the label*/label { position: relative; display: block; cursor: pointer;}
/*show the submenu when input is checked*/input:checked~ul.submenu { display: block;}
<input id="check01" type="checkbox" name="menu" /><label for="check01">Menu</label><ul class="submenu"> <li><a href="#">Item 1</a></li> <li><a href="#">Item 2</a></li></ul>
Making drop down menus with CSS (Is is possible)?
Simply add the following css
li ul{
position:absolute; // if you don't apply this it'll push the other menu items to right
display:none;
}
li:hover ul{
display:block;
}
check this JSFiddle
Update
If you want the submenu to be vertical, remove the float:left
for li
and add the following
li {
display:inline-block;
}
li ul li{
display:block;
}
check this JSFiddle
Making Animated Dropdown Menu by Using Pure CSS Like Bootstrap does
DEMO
html, body { margin:0;}.acn-menu { text-align: center; background-color: rgba(0, 0, 0, 0.9); border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; min-height: 74px; width: 100%;}.label_openclose { display: none;}.menu-tabs { height: 100%;}.menu-tabs .elem { box-sizing: border-box; padding: 0 20px; float: left; height: 100%; line-height: 70px; background-color: rgb(30, 30, 30); color: white;}@-webkit-keyframes spin { 0% { transform: rotate(-180deg); } 50% { transform: rotate(180deg); } 100% { transform: rotate(-180deg); }}@keyframes spin { 0% { transform: rotate(-180deg); } 50% { transform: rotate(180deg); } 100% { transform: rotate(-180deg); }}.menu-check:checked ~ .label_openclose { -webkit-animation-play-state: paused; animation-play-state: paused;}.menu-check { display: none;}.menu-tabs .elem:hover { background-color: rgba(255, 255, 255, 0.2);}/*@media screen and (max-width:55%)*/ @media screen and (max-width:768px) { .label_openclose { -webkit-animation: spin 2s; animation: spin 2s; display: inline-block; transform: rotate(-180deg); transition-duration: 1s; margin: 10px; width: 30px; height: 30px; border-radius: 50%; border-top: 10px solid rgb(50, 50, 50); border-right: 10px solid rgb(100, 100, 100); border-bottom: 10px solid rgb(150, 150, 150); border-left: 10px solid rgb(200, 200, 200); background-color: transparent; cursor: pointer; } .label_openclose:hover { transform: rotate(180deg); } .menu-tabs .elem { transition: border 1s linear, height 1s; line-height: initial; float: initial; height: 0px; cursor: pointer; border-top: 0px solid #000; overflow: hidden; } .menu-tabs:hover .elem { height: 25px; } .menu-check:checked ~ .menu-tabs .elem { height: 25px; color: white; border-top: 2px solid rgba(255, 255, 255, 0.2); } .label_openclose:hover ~ .menu-tabs .elem { border-top: 2px solid rgba(255, 255, 255, 0.2); height: 25px; }}
<div class="acn-menu"> <input type="checkbox" id="openclose" class="menu-check" /> <label class="label_openclose" for="openclose"></label> <div class="menu-tabs"> <div class="elem">test</div> <div class="elem">nav</div> <div class="elem">bar</div> <div class="elem">with</div> <div class="elem">transitions</div> </div></div><main> test content of main page</main>
How to make pure css dropdown menu work with two re-directable links withim them?
That is because you have set pointer-events: none
for the unordered list. This affects it's children <li>
as well.
.contact ul,
.contact-a ul {
position: absolute;
left: -10vw;
margin-top: 20px;
width: 300px;
height: 150px;
font-size: 1.5rem;
font-weight: bold;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: flex-end;
list-style: none;
text-transform: uppercase;
font-size: 1rem;
opacity: 0;
pointer-events: none; <<<<<<<<<<<<<<<<<<<< cause of problem
transform: translateY(-10px);
transition: all 0.4s ease;
}
Better remove that.
Pure CSS dropdown menu with collapse/hide option
Solution using hovers:
Leverages the focus-like state of :hover
in mobile browsers - the trick is to put the hover on an ancestor that will always be considered "hovered" when anything anywhere in the children are as well. Very clean and semantically correct. Check out the fiddle
html,body { height: 100%; width: 100%; background: #FFF;}
* { margin: 0; padding: 0; box-sizing:border-box;}
p { padding: 1.6em 0 0;}
.pretendthisisthebody { padding: 50px 10px 0;}
#hideholder { display: none;}
.radionav { position: absolute; top: 0; left: 0; background: #f8f8f8; width: 100%;}
.radionav>div { text-align: center; text-transform: uppercase;}
.radionav div,.radionav a { color: #505050; display: block; padding: 10px; width: 100%; cursor: pointer; text-decoration: none; transition: 0.1s all ease-in-out;}
.radionav li:hover>div{ background: #cc0000; color: #fff;}
.radionav ul { list-style-type: none; background: #f8f8f8;}
.radionav ul ul a { padding-left: 30px;}
.radionav input,.radionav .closer,.radionav ul,.radionav input:checked ~ .opener { display: none;}
.radionav:hover>ul,.radionav li:hover>ul { display: block;}
.radionav div::after { content: " +";}
@media all and (min-width: 481px) { .radionav>div { display: none !important; } .radionav>ul { display: block !important; } .radionav>ul>li { display: inline-block; } .radionav a, .radionav div { width: auto; } .radionav li { position: relative; } .radionav a:hover { background: #cc0000; color: #fff; } .radionav ul ul { position: absolute; top: 100%; left: 0; } .radionav ul ul li { display: block; min-width: 100%; } .radionav ul ul a { padding-left: 10px; white-space: nowrap; } .radionav li:hover>ul { display: block; } .radionav div::after { content: ""; }}
<div class="pretendthisisthebody"> <nav class="radionav"> <div>Menu</div> <ul> <li><a href="#">Menu item 0</a></li> <li> <div>Menu item 1</div> <ul> <li><a href="#">Just a link</a></li> <li><a href="#">Just a longer link</a></li> <li><a href="#">Just a link</a></li> </ul> </li> <li><a href="#">Menu item 2</a></li> <li><a href="#">Menu item 3</a></li> <li> <div>Menu item 4</div> <ul> <li><a href="#">Just a link</a></li> <li><a href="#">Just a longer link</a></li> <li><a href="#fail">Just a link</a></li> </ul> </li> <li><a href="#">Menu item 5</a></li> </ul> </nav>
<h1>Clicking in the body outside the menu will hide it</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur blandit aliquam suscipit. Vivamus ac mi tellus. Donec vulputate sem eu justo ornare, at mattis augue tempor. Nullam fringilla odio lobortis bibendum lobortis. Fusce condimentum ultricies nulla, non posuere sem vestibulum nec. Duis rhoncus velit lobortis odio interdum, quis aliquam ex dapibus. Quisque hendrerit pellentesque turpis non pretium. Nam ante metus, tempus quis tortor lacinia, efficitur ullamcorper erat. Sed at aliquet nisi, ac congue massa.</p> <p>Mauris est odio, tempor in ex ac, cursus iaculis ex. Etiam eu dapibus dolor. Quisque sodales mollis neque fringilla maximus. Praesent malesuada vitae elit eu congue. Mauris fringilla maximus arcu sit amet tempor. Nam sagittis lectus massa, eu viverra enim congue a. Nunc ultrices sapien nec enim auctor, ac placerat velit posuere. Donec velit ex, consectetur vitae sapien eget, eleifend maximus sem. Sed placerat nibh mi, eget fermentum justo ultrices nec.</p></div>
Drop-down menu that opens up/upward with pure css
Add bottom:100%
to your #menu:hover ul li:hover ul
rule
Demo 1
#menu:hover ul li:hover ul {
position: absolute;
margin-top: 1px;
font: 10px;
bottom: 100%; /* added this attribute */
}
Or better yet to prevent the submenus from having the same effect, just add this rule
Demo 2
#menu>ul>li:hover>ul {
bottom:100%;
}
Demo 3
source: http://jsfiddle.net/W5FWW/4/
And to get back the border you can add the following attribute
#menu>ul>li:hover>ul {
bottom:100%;
border-bottom: 1px solid transparent
}
How to make pure CSS dropdown menu appear with a fade in/slowly
You should use CSS3 Animations, although they aren't supported in all browsers such as <=IE9, this is exactly what they were made for. You may want to try jQuery for older browsers.
Workign demo JSFiddle
li:hover > ul {
display: block;
opacity: 0;
z-index: 98;
position: absolute;
-webkit-animation: fadein 2s; /* Safari and Chrome */
-moz-animation: fadein 2s; /* Firefox */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera */
animation: fadein 2s;
}
@keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox */
@-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari and Chrome */
@-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
@-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Opera */
@-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
Related Topics
How to Expand Floated Child Div'S Height to Parent'S Height
Minimum and Maximum Value of Z-Index
How to Get HTML 5 Input Type="Date" Working in Firefox And/Or Ie 10
How Does Jquery Work When There Are Multiple Elements With the Same Id Value
How Create Table Only Using ≪Div≫ Tag and Css
Overlay Opaque Div Over Youtube Iframe
:After and :Before CSS Pseudo Elements Hack For Internet Explorer 7
Ie8 Support For CSS Media Query
Input Type="Submit" VS Button Tag Are They Interchangeable
Add Border-Bottom to Table Row ≪Tr≫
When to Use the !Important Property in Css
Why Can't I Have a Numeric Value as the Id of an Element
Is There an Equivalent to Background-Size: Cover and Contain For Image Elements
Why Can't I Center With Margin: 0 Auto
How to Apply CSS Page-Break to Print a Table With Lots of Rows