Skip to main content

Pure CSS3 Responsive DropDown Button and Menu


Pure CSS3 Responsive DropDown Button and Menu




CSS3 Responsive DropDown Button





In this tutorial We are going to take a look at a CSS only technique for creating dropdowns.We will create pure css3 DropDown button without a single line of JavaScript.







You can see the example in action in our editor. Click the HTML and "CSS" button to see the code. You can Download the full source code from the button above.









The Markup




This is what our HTML structure looks like. Here it’s important to note, that the input element has to come first, before the label and before the ul. You will understand why this is needed later, when we check out the CSS.



<div class="dropdown">
<input type="checkbox" id="checkbox_toggle">
<label for="checkbox_toggle">Click to Expand</label>
<ul>
<li><a href="#">Link One</a></li>
<li><a href="#">Link Two</a></li>
<li><a href="#">Link Three</a></li>
<li><a href="#">Link Four</a></li>
</ul>
</div>




As you can see, there’s nothing out of the ordinary here, all of elements are in standard, frequently used HTML:




  • The div will serve as a container for the whole thing.

  • The input type=checkbox is needed because of it’s checked/unchecked property. It will be hidden at all times

  • The label will be used to toggle the input and will also serve as the trigger for your dropdown.

  • The ul is simply a list we want to be visible when the dropdown is extended. Can be any other element.






The CSS




body{
text-align: center;
font: 16px/1.5 sans-serif;
padding-top: 40px;
background-color: #ECEFF1;
}



.dropdown{
position: relative;
display: inline-block;
font-size: 16px;
color: #FFF;
}

/**
Hide the checkbox itself. Checking and unchecking
it we will be done via the label element.
*/

input[type=checkbox]{
display: none;
}


/* Click to expand button */

label{
box-sizing: border-box;
display: inline-block;
width: 100%;
background-color: #57A0D4;
padding: 15px 20px;

cursor: pointer;
text-align: center;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

input[type=checkbox]:checked ~ ul {
display: block
}

/* The ul will have display:none by default */

ul{
position: absolute;
list-style: none;
text-align: left;
width: 100%;
z-index: 1;
margin:0;
padding:0;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2);

display: none;
}


ul li{
padding: 15px;
background-color: #fff;
color: #4FB9A7;
margin-bottom: 1px;
cursor: pointer;
}

ul li:hover{
background-color: #4FB9A7;
color: #FFF;
}

ul li a{
color: inherit;
text-decoration: none;
}


/**

By using the Following-sibling selector (~),
we can target elements positioned after our checkbox in the DOM tree.

With the state pseudo selector (:checked),
we can make changes depending on the state of the checkbox.

Using this combination of selectors
allows to change the color of the label
and show the list of items
only when the checkbox is checked.

*/

input[type=checkbox]:checked ~ label {
background-color: #3D88BD;
}


input[type=checkbox]:checked ~ ul {
display: block;
}








Hope you enjoyed our quick tip!






Comments

Popular posts from this blog

Codecanyon-King MEDIA v1.9.7 | Nulled Script | free download

King Media v1.9.7 Preview   Screenshots Download About King Media KingMedia is a content sharing script suitable for different posts formats: image upload image share from different hosts video posts with automated thumbnails creation Technical Info Created Updated High Resolution Compatible Browsers Files Software Version 5 June 14 27 May 15 Yes IE11, Firefox, Safari, Opera, Chrome JavaScript JS, JavaScript JSON, HTML, CSS, PHP PHP 4.x, PHP 5.x, PHP 5.0 - 5.2, PHP 5.3, PHP 5.4 Features Image Upload & Share From Url , Youtube, Facebook, Vimeo, VK, Vine, Instagram, Metacafe, DailyMotion Videos and Soundcloud Comments for Media Facebook Comments Responsive Layout User Profile & Points Tags or Category System Super Easy Installation Full Admin Panel Moderate Guest Submissions Social Share Buttons Search for Media Seo Url Much More… Gold Media Reviews Download Now! Requirements PHP 4.3 or later, PHP 5.4.x for all functionality. MySQL 4.1 or ...

Opera Browser Offline Installer Latest Version Free Download(Win+Mac+Linux+Android)

Opera Browser About Opera Browser Download Opera Browser Offline Installer Latest Version.Opera is also available in both offline and live installer.Opera products enable more than 350 million internet consumers to discover and connect with the content and services that matter most to them, no matter what device, network or location. In turn, we help advertisers reach the audiences that build value for their businesses. Opera also delivers products and services to more than 120 operators around the world, enabling them to provide a faster, more economical and better network experience to their subscribers. From family photos and funny videos to business ideas that change the world economy, the internet has always been about discovery. Whether you are a consumer getting online for the first time, or a multinational corporation trying to reach the right audience, Opera can help you discover more online. Opera for Windows Opera browser – Do more on the web Opera Features Stay in sync Eas...

The 15 Most Stunningly Colorful Natural Wonders on Earth

The 15 Most Stunningly Colorful Natural Wonders on Earth Posted By  Stumbli on Jun 26,2018 Inspiration True Stories Look up at the sky, down at the ground, or out into the landscape, and you’ll see that our planet is a fascinating prism of hues, from multicolored mountains and deserts to astronomical curiosities and kaleidoscopic rivers. Bioluminescent waters in Tasmania If you’ve ever seen a firefly, then you’ve witnessed bioluminescence—a pulsating glow emitted by living organisms. Most bioluminescent creatures are marine life, though, and when they light up underwater, the whole sea seems to magically sparkle. There are plenty of these kinds of waters throughout the world, but the River Derwent in Tasmania offers a double whammy in the spring: bioluminescent waves, right beneath the Aurora Australis, a natural electric phenomenon that creates a technicolor sky. Rainbow eucalyptus groves in Maui, Hawaii The iconic Painted Forest on the road to Hana, Maui is saturated with eucalyp...