Use only CSS to switch the tabs. Find the demo at end of the tutorial.
Creating A Stylish Tabs Control Using Pure CSS / CSS3. Pure CSS3 Tabs using radio button is hidden. Make the radio inputs act as tabs 🙂
HTML Code
<div data-tabs class="tabs">
<div class="tab">
<input type="radio" name="tabgroup" id="tab-1" checked>
<label for="tab-1">Tab 1</label>
<div class="tab__content">
<h4>Tab heading 1</h4>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Incidunt libero ipsum, veniam magni modi exercitationem debitis ducimus assumenda ratione corporis, illum eius, laborum tempore amet id perspiciatis nostrum unde?</p>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Ipsum, maiores.</p>
</div>
</div>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-2">
<label for="tab-2">Tab 2</label>
<div class="tab__content">
<h4>Tab heading 2</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur odio eveniet excepturi eum provident molestias ad ipsa unde dignissimos illo porro animi earum aliquam perspiciatis id omnis, adipisci incidunt. Qui, beatae. Beatae animi totam obcaecati at quae, iste facere fuga nemo pariatur esse nihil?</p>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloremque commodi eos voluptatem numquam pariatur deleniti repellat fugiat eligendi nulla molestiae sunt praesentium vero sequi distinctio error quibusdam maiores natus magnam, explicabo hic sed alias dolores, quis eum! Reprehenderit atque cupiditate dolorum? Saepe, doloribus veniam? Nulla!</p>
</div>
</div>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-3">
<label for="tab-3">Tab 3</label>
<div class="tab__content">
<h4>Tab heading 3</h4>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam officiis voluptas maiores deserunt ullam aliquam?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusamus, officia accusantium quod fuga porro eius animi earum excepturi omnis! Reprehenderit!</p>
</div>
</div>
<div class="tab">
<input type="radio" name="tabgroup" id="tab-4">
<label for="tab-4">Tab 4</label>
<div class="tab__content">
<h4>Tab heading 4</h4>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officia exercitationem veritatis vero eaque. Nam totam dolorem sapiente ullam non sed nostrum praesentium voluptatem, ad quam libero deserunt nemo fuga hic repudiandae veritatis cupiditate, mollitia recusandae!</p>
</div>
</div>
</div>
CSS Code
@import url('https://fonts.googleapis.com/css?family=Open+Sans');
body {
font-family: 'Open Sans', sans-serif;
background-color: #C2EABA;
padding-top: 50px;
line-height: 1.4;
font-size: 1.4em;
}
.tabs {
clear: both;
position: relative;
max-width: 650px;
margin: 0 auto;
min-height: 500px;
}
.tab {
float: left;
}
.tab label {
margin-right: 20px;
position: relative;
top: 0;
cursor: pointer;
color: #333;
text-transform: uppercase;
}
.tab [type=radio] {
display: none;
}
.tab__content {
position: absolute;
top: 40px;
left: 0;
right: 0;
bottom: 0;
transition: opacity .2s cubic-bezier(.42,0,.34,1.01);
opacity: 0;
}
[type=radio]:checked ~ label {
border-bottom: 2px solid #1d1d1d;
color: #1d1d1d;
z-index: 2;
}
[type=radio]:checked ~ label ~ .tab__content {
z-index: 1;
opacity: 1;
}
Leave a Reply