Табы с js
by akogch
HTML
<div class="about">Pen by <a href="https://rafaelalucas.com" target="_blank">Rafaela Lucas</a> <span class="one"></span> Follow me on: <a href="https://dribbble.com/rafaelalucas" target="_blank">Dribbble</a> <span class="two"></span> <a href="https://www.linkedin.com/in/rafaelalucas/"
target="_blank">LinkedIn</a></div>
<section id="wrapper">
<div class="content">
<!-- Tab links -->
<div class="tabs">
<button class="tablinks active" data-country="London"><p data-title="London">London</p></button>
<button class="tablinks" data-country="Paris"><p data-title="Paris">Paris</p></button>
<button class="tablinks" data-country="Barcelona"><p data-title="Barcelona">Barcelona</p></button>
<button class="tablinks" data-country="Madrid"><p data-title="Madrid">Madrid</p></button>
</div>
<!-- Tab content -->
<div class="wrapper_tabcontent">
<div id="London" class="tabcontent active">
<h3>London</h3>
<p>London is the capital of Great Britain. It is one of the greatest cities in the world. It is an important business and financial centre. It is an intellectual centre, too. Everywhere in London, there are open spaces: Hyde Park and Regent Park
are the largest. The City is the oldest part of London. </p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is in the Paris department of the Paris-Isle-of-France region The French historic, political and economic capital, with a population of only 2.5 million is located in the northern part of France. One of the most beautiful cities in the world.
Home to historical monuments such as Notre Dame, the Eiffel tower (320m), Bastille, Louvre and many more. </p>
</div>
<div id="Barcelona" class="tabcontent">
<h3>Barcelona</h3>
<p>Barcelona has been an urban laboratory since the high Medieval Ages. A place of diversity, a backdrop for a multiplicity of social and cultural...
CSS
@import url("https://fonts.googleapis.com/css?family=IBM+Plex+Mono:400,400i|IBM+Plex+Sans+Condensed:400,400i|IBM+Plex+Sans:100,100i,400,400i,700,700i|IBM+Plex+Serif:400,400i");
/* main 1*/
/* main 2*/
/* neutral 1*/
/* neutral 2*/
body {
background-color: #2e2e2e;
font-family: "IBM Plex Sans", sans-serif;
margin: 0;
}
.about {
@import url("https://fonts.googleapis.com/css?family=Rubik:300,400");
background-color: #2c303a;
width: 100%;
min-width: 480px;
height: 50px;
position: absolute;
bottom: 0;
color: #888888;
display: flex;
justify-content: center;
align-items: center;
font-family: "Rubik", sans-serif;
text-transform: uppercase;
font-size: 12px;
letter-spacing: 1px;
font-weight: 300;
z-index: 3;
border-bottom: solid 1px #131418;
}
.about a {
color: white;
margin: 0 5px;
padding: 2px 3px;
text-decoration: none;
position: relative;
transition: all 0.3s ease;
z-index: 1;
display: flex;
align-items: center;
}
.about a:after {
content: "";
position: absolute;
width: calc(100% - 6px);
height: 1px;
background-color: #46b7a7;
bottom: 0;
transition: all 0.3s ease;
}
.about a:before {
content: "";
position: absolute;
width: 0;
height: 0px;
background-color: #46b7a7;
right: 0;
bottom: 0;
transition: all 0.3s 0.3s ease;
z-index: -1;
}
.about a:hover:after {
width: 0;
left: 0;
}
.about a:hover:before {
width: 100%;
height: 100%;
left: 0;
}
.about .one {
width: 2px;
height: 20px;
background-color: #444857;
margin: 0 10px 0 5px;
}
.about .two {
width: 4px;
height: 4px;
border-radius: 100%;
background-color: #444857;
margin: 0 5px;
}
#wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
.content {
max-width: 600px;
width: 100%;
min-width: 260px;
margin: 0 5%;
margin-top: 10%;
transition: 0.3s ease;
}
@media screen and (max-width: 512px) {
.content {
margin: 0 4%;
margin-top: 5%;
...
JavaScript
// tabs
var tabLinks = document.querySelectorAll(".tablinks");
var tabContent = document.querySelectorAll(".tabcontent");
tabLinks.forEach(function(el) {
el.addEventListener("click", openTabs);
});
function openTabs(el) {
var btnTarget = el.currentTarget;
var country = btnTarget.dataset.country;
tabContent.forEach(function(el) {
el.classList.remove("active");
});
tabLinks.forEach(function(el) {
el.classList.remove("active");
});
document.querySelector("#" + country).classList.add("active");
btnTarget.classList.add("active");
}