JSFiddle - React, Tailwind, and code Playground
by Anisuzzaman Khan
HTML
<div class="container">
<div class="tabs">
<ul>
<li class="active" data-tab="1">Slide 1</li>
<li data-tab="2">Slide 2</li>
<li data-tab="3">Slide 3</li>
</ul>
</div>
<div class="tab-wrapper">
<div class="tab active" data-slide="1">
<div class="overflow">
<div class="show"></div>
</div>
</div>
<div class="tab" data-slide="2">
<div class="overflow">
<div class="show"></div>
</div>
</div>
<div class="tab" data-slide="3">
<div class="overflow">
<div class="show"></div>
</div>
</div>
</div>
</div>
CSS
.container {
width:800px;
margin:0 auto;
background:#999999;
}
ul {
list-style-type:none;
display:table;
width:100%;
}
li {
display:table-cell;
color:#ffffff;
}
li.active {
color:blue;
}
.tab-wrapper {
width:800px;
height:300px;
border-top:solid 20px #ffffff;
}
.tab {
width:0px;
height:300px;
position:absolute;
background:#666666;
-webkit-transition:width 1s ease;
}
.tab.active {
width: 800px;
}
.overflow {
width:100%;
height:100%;
border:solid 3px red;
overflow:hidden;
position:relative;
}
.tab.active .overflow {
width:100%;
}
[data-slide="1"] .show {
width:800px;
height:200px;
top:50px;
position:absolute;
background:yellow;
}
[data-slide="2"] .show {
width:800px;
height:200px;
top:50px;
position:absolute;
background:green;
}
[data-slide="3"] .show {
width:800px;
height:200px;
top:50px;
position:absolute;
background:blue;
}
JavaScript
$('.tabs li').click(function () {
var tab = $(this).data('tab');
var picked = $('.tab').data('slide', tab);
$('.tabs li.active').removeClass('active');
$('.tab.active').removeClass('active');
$(this).addClass('active');
$('.tab[data-slide=' + tab + ']').addClass('active');
});