A Pen by Joseph Fusco on CodePen.
Created
July 7, 2015 13:23
-
-
Save mtinra/56d38023d970c42be895 to your computer and use it in GitHub Desktop.
CSS Tabs - Transitioning Between Variable Heights
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
<h1>CSS Tabs</h1> | |
<h2>Transitioning Between Variable Heights</h2> | |
<div class="container"> | |
<div class="demo-section"> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
</div> | |
<div class="tab-wrap"> | |
<input type="radio" id="tab1" name="tabGroup1" class="tab" checked> | |
<label for="tab1">Short</label> | |
<input type="radio" id="tab2" name="tabGroup1" class="tab"> | |
<label for="tab2">Medium</label> | |
<input type="radio" id="tab3" name="tabGroup1" class="tab"> | |
<label for="tab3">Long</label> | |
<div class="tab__content"> | |
<h3>Short Section</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Medium Section</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
<p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Long Section</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
<p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
<p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
</div> | |
</div> | |
<div class="demo-section"> | |
<p>Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. Phasellus volutpat, metus eget | |
egestas mollis, lacus lacus blandit dui, id egestas quam mauris ut lacus. Praesent nec nisl a purus blandit viverra. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p> | |
<p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
</div> | |
<div class="tab-wrap"> | |
<input type="radio" id="tab4" name="tabGroup2" class="tab" checked> | |
<label for="tab4">Apples</label> | |
<input type="radio" id="tab5" name="tabGroup2" class="tab"> | |
<label for="tab5">Oranges</label> | |
<input type="radio" id="tab6" name="tabGroup2" class="tab"> | |
<label for="tab6">Bananas</label> | |
<input type="radio" id="tab7" name="tabGroup2" class="tab"> | |
<label for="tab7">Kiwis</label> | |
<input type="radio" id="tab8" name="tabGroup2" class="tab"> | |
<label for="tab8">Tomatos</label> | |
<div class="tab__content"> | |
<h3>Apples</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Oranges</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
<p>In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Bananas</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Kiwis</h3> | |
<p>Praesent nonummy mi in odio.</p> | |
</div> | |
<div class="tab__content"> | |
<h3>Tomatos</h3> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum.</p> | |
</div> | |
</div> | |
<div class="demo-section"> | |
<p>Etiam ut purus enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Morbi mattis ullamcorper velit. Pellentesque posuere. Etiam ut purus mattis mauris sodales aliquam. Praesent nec nisl a purus blandit viverra.</p> | |
<p>Praesent nonummy mi in odio. Nullam accumsan lorem in dui. Vestibulum turpis sem, aliquet eget, lobortis pellentesque, rutrum eu, nisl. Nullam accumsan lorem in dui. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</p> | |
</div> | |
</div> |
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
$max-tab-count: 5; | |
$tab-wrap-border-radius: 6px; | |
@import url(http://fonts.googleapis.com/css?family=Maven+Pro); | |
.tab-wrap { | |
transition: 0.3s box-shadow ease; | |
border-radius: $tab-wrap-border-radius; | |
max-width: 100%; | |
display: flex; | |
flex-wrap: wrap; | |
position: relative; | |
list-style: none; | |
background-color: #fff; | |
margin: 40px 0; | |
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); | |
&:hover { | |
box-shadow: 0 12px 23px rgba(0,0,0,0.23), 0 10px 10px rgba(0,0,0,0.19); | |
} | |
} | |
.tab { | |
display: none; | |
@for $i from 1 through $max-tab-count { | |
&:checked:nth-of-type(#{$i}) ~ .tab__content:nth-of-type(#{$i}){ | |
opacity: 1; | |
transition: 0.5s opacity ease-in, 0.8s transform ease; | |
position: relative; | |
top: 0; | |
z-index: 100; | |
transform: translateY(0px); | |
text-shadow: 0 0 0; | |
} | |
} | |
&:first-of-type:not(:last-of-type) + label { | |
border-top-right-radius: 0; | |
border-bottom-right-radius: 0; | |
} | |
&:not(:first-of-type):not(:last-of-type) + label { | |
border-radius: 0; | |
} | |
&:last-of-type:not(:first-of-type) + label { | |
border-top-left-radius: 0; | |
border-bottom-left-radius: 0; | |
} | |
&:checked + label { | |
background-color: #fff; | |
box-shadow: 0 -1px 0 #fff inset; | |
cursor: default; | |
&:hover { | |
box-shadow: 0 -1px 0 #fff inset; | |
background-color: #fff; | |
} | |
} | |
+ label { | |
box-shadow: 0 -1px 0 #eee inset; | |
border-radius: $tab-wrap-border-radius $tab-wrap-border-radius 0 0; | |
cursor: pointer; | |
display: block; | |
text-decoration: none; | |
color: #333; | |
flex-grow: 3; | |
text-align: center; | |
background-color: #f2f2f2; | |
user-select: none; | |
text-align: center; | |
transition: 0.3s background-color ease, 0.3s box-shadow ease; | |
height: 50px; | |
box-sizing: border-box; | |
padding: 15px; | |
&:hover { | |
background-color: #f9f9f9; | |
box-shadow: 0 1px 0 #f4f4f4 inset; | |
} | |
} | |
&__content { | |
padding: 10px 25px; | |
background-color: transparent; | |
position: absolute; | |
width: 100%; | |
z-index: -1; | |
opacity: 0; | |
transform: translateY(-3px); | |
border-radius: $tab-wrap-border-radius; | |
} | |
} | |
/* boring stuff */ | |
body { | |
font-family: 'Maven Pro', sans-serif; | |
background-color: #e7e7e7; | |
color: #777; | |
padding: 30px 0; | |
} | |
.container { | |
margin: 0 auto; | |
display: block; | |
max-width: 800px; | |
> *:not(.tab-wrap){ | |
padding: 0 80px; | |
} | |
} | |
h1, h2 { | |
margin: 0; | |
color: #444; | |
text-align: center; | |
} | |
h2 { | |
font-size: 1em; | |
margin-bottom: 30px; | |
} | |
p { | |
line-height: 1.6; | |
margin-bottom: 20px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment