Skip to content

Instantly share code, notes, and snippets.

@leobalter
Forked from anonymous/index.html
Last active August 29, 2015 14:21
Show Gist options
  • Save leobalter/f303e902ce4f83fe22da to your computer and use it in GitHub Desktop.
Save leobalter/f303e902ce4f83fe22da to your computer and use it in GitHub Desktop.
CSS Dropdown Menu

CSS Dropdown Menu

('-' * 6)

A Pen by Leo Balter on CodePen.

License

Copyright (c) 2015 by Leonardo Balter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<div class="dropdown">
<input type="checkbox" name="foo-input" id="foo-input" class="expand-input" autocomplete="off" />
<label for="foo-input" class="expand-label">Foo Menu - Click here to toggle</label>
<nav class="expand-block">
<ul>
<li><a href="">Foo 1</a></li>
<li><a href="">Foo 2</a></li>
<li><a href="">Foo 3</a></li>
<li><a href="">Foo 4</a></li>
<li><a href="">Foo 5</a></li>
</ul>
</nav>
</div>
.dropdown {}
.expand-label {
background: #e7e7e7;
}
.expand-block {
opacity: 0;
transition: all .4s linear;
position: relative;
overflow: hidden;
z-index: 10;
height: 0;
}
.expand-input:checked ~ .expand-label {
background-color: #ffe7e7;
}
.expand-input:checked ~ .expand-block {
opacity: 1;
height: initial;
}
/* The CSS Below is irrelevant */
.expand-label {
display: block;
padding: 10px;
border: 1px solid #ccc;
cursor: pointer;
}
.expand-input {
display: none;
}
.expand-block ul {
padding-left: 0;
margin: 0;
}
.expand-block li {
border: 1px solid #ccc;
list-style: none inside;
}
.expand-block a {
display: block;
text-decoration: none;
padding: 10px;
}
.expand-block li + li {
margin-top: 2px;
}
@rafaellyra
Copy link

Very nice, but why the first line has a selector without rules?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment