public
Created

Click open/close Dropdown in pure CSS

  • Download Gist
dabblet.css
CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
 
/* Click open/close Dropdown in pure CSS */
 
 
/* Disclaimer: Not the most semantic
thing in the universe. */
/* Forked from original idea
http://jsfiddle.net/paullferguson/Sv54G/3/ */
 
 
.tabs {
position: relative;
clear: both;
margin: 50px;
}
.tab {
float: left;
position: relative;
}
.tab label {
background: linear-gradient(#eee, #ccc);
padding: 10px 30px;
cursor: pointer;
text-align: center;
display: block;
position: relative;
}
.tab label i {
font-style: normal;
font-size: 10px;
color: #aaa;
}
.tab [type=radio] {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
margin: 0;
z-index: 1;
}
.content {
position: absolute;
top: 100%;
opacity: 0;
left: 0;
background: #333;
color: white;
padding: 20px;
}
.content ul {
margin: 0;
padding: 0;
list-style: none;
}
.content a {
color: white;
display: block;
white-space: nowrap;
text-decoration: none;
border-bottom: 1px solid #999;
padding: 5px;
}
[type=radio]:checked ~ label {
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
opacity: 1;
}
 
 
.close-tab {
position: absolute;
z-index: -1;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.close-tab label {
background: #333;
color: white;
}
[type=radio]:checked ~ label ~ .close-tab {
z-index: 3;
}
dabblet.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 
<div class="tabs">
 
 
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1">
<label for="tab-1">List 1 <i></i></label>
<div class="tab close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 1 <i></i></label>
</div>
 
 
<div class="content">
<ul>
<li><a href="#">Menu Item #1</a></li>
<li><a href="#">Menu Item #2</a></li>
<li><a href="#">Really Long Menu Item #3</a></li>
<li><a href="#">Menu Item #4</a></li>
<li><a href="#">Menu Item #5</a></li>
</ul>
</div>
</div>
 
 
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">List 2 <i></i></label>
<div class="tab close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 2 <i></i></label>
</div>
 
 
<div class="content">
Repeats the input and label. Gnarly, but it enables the functionality.
</div>
</div>
 
 
<div class="tab">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">List 3 <i></i></label>
<div class="tab close-tab">
<input type="radio" id="tab-close" name="tab-group-1">
<label for="tab-close">List 3 <i></i></label>
</div>
 
 
<div class="content">
Worked on iOS 5. And modern browsers of course. Probably something like IE 9+ too.
</div>
</div>
 
 
</div>
settings.json
JSON
1
{"view":"split-vertical","prefixfree":"1","page":"result"}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.