Last active
September 16, 2015 22:52
-
-
Save duongphuhiep/d343c60bfc53f73a1324 to your computer and use it in GitHub Desktop.
tabs panel in pure CSS thanks to http://csscience.com/css3-tabs/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | |
<style type="text/css" media="screen"> | |
* { | |
box-sizing: border-box; | |
} | |
input { | |
display: none; | |
} | |
.tab-title { | |
position:relative; /*for #require 1*/ | |
cursor: pointer; | |
/* display: block;*/ | |
float: left; | |
background: #ccc; | |
border: 1px solid #888; | |
border-left: 0; | |
border-bottom: 0; | |
white-space: nowrap; | |
width: 33.33%; | |
} | |
.tab-link { | |
overflow: hidden; | |
text-align: center; | |
margin:10px; | |
} | |
.tab-title:hover { | |
background: #eee; | |
} | |
.tab-title:nth-of-type(1) { | |
border-left: 1px solid #888; | |
} | |
.tab { | |
clear: both; | |
background: #ddd; | |
display: none; | |
border: 1px solid #888; | |
} | |
@media only screen and (max-width: 1150px) { | |
} | |
#tab-C:checked ~ label:nth-of-type(3), | |
#tab-B:checked ~ label:nth-of-type(2), | |
#tab-B:not(:checked) ~ #tab-C:not(:checked) ~ label:nth-of-type(1) { | |
background: #ddd; | |
} | |
#tab-C:checked ~ label:nth-of-type(3):after, | |
#tab-B:checked ~ label:nth-of-type(2):after, | |
#tab-B:not(:checked) ~ #tab-C:not(:checked) ~ label:nth-of-type(1):after { | |
position: absolute; | |
width:100%; /*#require 1: only work if parent position must be different static*/ | |
content: ""; | |
height:1px; | |
/*display: block;*/ | |
background: #ddd; | |
} | |
input:nth-of-type(2):not(:checked) ~ input:nth-of-type(3):not(:checked) ~ .tab:nth-of-type(1), | |
input:nth-of-type(2):checked ~ .tab:nth-of-type(2), | |
input:nth-of-type(3):checked ~ .tab:nth-of-type(3) | |
{ | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<section> | |
<input checked type="radio" name="tab" id="tab-A" /> | |
<input type="radio" name="tab" id="tab-B" /> | |
<input type="radio" name="tab" id="tab-C" /> | |
<label class="tab-title" for="tab-A"><div class="tab-link">Tab 1: Lorem</div></label> | |
<label class="tab-title" for="tab-B"><div class="tab-link">Tab 2: Lorem ipsum Fugiat occaecat dolor voluptate esse</div></label> | |
<label class="tab-title" for="tab-C"><div class="tab-link">Tab 3</div></label> | |
<article class="tab"> | |
<h3>I love :checked. :checked is great. If only I could toggle any item and not just input elements we'd be golden.</h3> | |
</article> | |
<article class="tab"> | |
<h3>Tab 2</h3> | |
<p>Lorem Ipsum Dolor Sit</p> | |
</article> | |
<article class="tab"> | |
<h3>Tab 3</h3> | |
<p>Lorem Ipsum Dolor Sit</p> | |
</article> | |
</section> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This version is more responsive (mobile friendly), tested with Firefox and Chrome