Skip to content

Instantly share code, notes, and snippets.

@mf81bln
Created March 9, 2014 21:37
Show Gist options
  • Save mf81bln/9455070 to your computer and use it in GitHub Desktop.
Save mf81bln/9455070 to your computer and use it in GitHub Desktop.
pure CSS menu, without JavaScript - adopted from http://jsfiddle.net/paullferguson/Sv54G/3/
html { overflow-y: scroll; }
.tabs {
position: relative;
min-height: 100px; /* This part sucks */
clear: both;
margin: 25px 0 60px 0;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
cursor: pointer;
width: 90px;
text-align: center;
display: block;
border: 1px solid #ccc;
margin-left: -1px;
position: relative;
left: 1px;
}
.tab label i {
font-style: normal;
font-size: 10px;
color: #aaa;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: 40px;
opacity: 0;
left: 0;
background: white;
right: 0;
bottom: 0;
padding: 0px 20px;
border: 1px solid #ccc;
height: 0;
-webkit-transition: all 400ms cubic-bezier(0.250, 0.460, 0.450, 0.940);
-moz-transition: all 400ms cubic-bezier(0.250, 0.460, 0.450, 0.940);
-ms-transition: all 400ms cubic-bezier(0.250, 0.460, 0.450, 0.940);
-o-transition: all 400ms cubic-bezier(0.250, 0.460, 0.450, 0.940);
transition: all 400ms cubic-bezier(0.250, 0.460, 0.450, 0.940);
}
[type=radio]:checked ~ label {
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
opacity: 1;
height: 100%;
padding: 20px;
}
#close-tab {
position: absolute;
z-index: -1;
top: 0px;
}
#close-tab label {
background: white;
border-bottom: 1px solid white;
}
[type=radio]:checked ~ label ~ #close-tab {
z-index: 3;
}
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1">
<label for="tab-1">List 1 <i>&#9660;</i></label>
<div class="tab" id="close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 1 <i>&#9650;</i></label>
</div>
<div class="content">
Experemental dropdowns - adding "drop down" and a close button to the "pure CSS tabs" by Chris Coyier - <a href="http://css-tricks.com/13758-functional-css-tabs-revisited/">http://css-tricks.com/13758-functional-css-tabs-revisited/</a>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">List 2 <i>&#9660;</i></label>
<div class="tab" id="close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 2 <i>&#9650;</i></label>
</div>
<div class="content">
Uses a second radio button within the tab which is grizzly I know but makes it collapsible.
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">List 3 <i>&#9660;</i></label>
<div class="tab" id="close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 3 <i>&#9650;</i></label>
</div>
<div class="content">
Got really excited about getting this working, but sadly IOS crushed the JS free dream :(
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment