I\'m currently trying to build a tabbed div container:
At the moment it looks like this. I can also switch the tab. Each tab has an is-active
c
Yes,you can do it using an extra tag. Call it as a slider
for now.
So, now if you click on the slider will move to and fro.
Here is code attached.
var tabs = document.getElementsByClassName('Tab');
Array.prototype.forEach.call(tabs, function(tab) {
tab.addEventListener('click', setActiveClass);
});
function setActiveClass(evt) {
Array.prototype.forEach.call(tabs, function(tab) {
tab.classList.remove('active');
});
evt.currentTarget.classList.add('active');
}
.Tabs {
position: relative;
background-color: #fff;
margin: 0;
padding: 0;
list-style: none;
}
.Tabs:after {
content: ' ';
display: table;
clear: both;
}
.description_tab {
float: left;
width: 33.333%;
text-align: center;
}
.description_tab:first-child.active ~ .slider {
left: 0;
}
.description_tab:nth-child(2).active ~ .slider {
left: 33.333%;
}
.slider {
position: absolute;
bottom: 0;
left: 0;
width: 33.333%;
height: 4px;
background-color: #4A66F4;
transition: left .25s;
}
.Tab {
font-family: 'Roboto Slab';
}
.Tab > a {
display: block;
padding: 10px 12px;
text-decoration: none;
color: #666;
transition: color .15s;
}
.Tab.active > a {
color: #222;
}
.Tab:hover > a {
color: #222;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<ul class="Tabs" role="tablist">
<li class="description_tab active Tab" id="tab-title-description" role="tab" aria-controls="tab-description">
<a href="#tab-description">Beschreibung</a>
</li>
<li class="description_tab Tab" id="tab-title-reviews" role="tab" aria-controls="tab-reviews">
<a href="#tab-reviews">Fragen / Antworten</a>
</li>
<li class="slider" role="presentation"></li></ul>
</body>
</html>
Hope this helped you, Thank you.
Credits: from earth on codepen