Custom Tabs

Posted on : 22nd May 2022 | Author : @ByDev24

						<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<div class="tab-container">
	<div class="tabs">
		<button type="button" class="active tab-btn" data="tab1">Tab 1</button>
		<button type="button" class="tab-btn" data="tab2">Tab 2</button>
		<button type="button" class="tab-btn" data="tab3">Tab 3</button>
		<button type="button" class="tab-btn" data="tab4">Tab 4</button>
	</div>
	<div class="tab-content active" data-content="tab1">
		<h4>Tab 1 Content</h4>
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
	</div>
	<div class="tab-content" data-content="tab2">
		<h4>Tab 2 Content</h4>
		<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable.</p>
		<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable.</p>
	</div>
	<div class="tab-content" data-content="tab3">
		<h4>Tab 3 Content</h4>
		<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
		<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
	</div>
	<div class="tab-content" data-content="tab4">
		<h4>Tab 4 Content</h4>
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
	</div>
</div>

					

						 body{
	font-family: 'Roboto', sans-serif;
	font-size: 14px;
}
.tab-container {width: 450px;max-width: 100%;padding: 10px;box-shadow: 0px 0px 10px #0000000d;border-radius: 10px;}

.tabs {display: flex;column-gap: 20px;margin-bottom: 30px;}

.tabs button {width: 100%;background: #e1e1e1;color: #000;border: none;padding: 10px 10px;cursor: pointer;border-bottom: 3px solid #e1e1e1;}

.tabs button:hover {border-color: #363636;}

.tabs button.active {background: #000;color: #fff;border-color: #000;}

.tab-content h4 {margin: 0 0 0 0;}

.tab-content p {line-height: 23px;}

.tab-content {display: none;}

.tab-content.active {display: block;}

					

						var tabs = document.getElementsByClassName("tab-btn");
var content = document.getElementsByClassName("tab-content");
for (var i = 0; i < tabs.length; i++) {
	tabs[i].addEventListener("click", function (e) {
		for(var j = 0; j < tabs.length; j++){
			tabs[j].classList.remove("active")
			content[j].classList.remove("active")
		}
		var targetContent = e.target.getAttribute("data")
		e.target.classList.add("active")
		document.querySelector("[data-content='"+targetContent+"']").classList.add("active")
	});
}

					

Output

More Snipps