How to makea responsive animated hover tab using html css and javascript

How to makea responsive animated hover tab using html css and javascript

Step 1: HTML

<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 processes on multiple scales that reflect different ways of constructing the future, a city with a long experience of urban life and social innovations. </p>
         </div>

         <div id="Madrid" class="tabcontent">
            <h3>Madrid</h3>
            <p>Madrid is in the middle of Spain, in the Community of Madrid. The Community is a large area that includes the city as well as small towns and villages outside the city. 7 million people live in the Community. More than 3 million live in the city itself.
            </p>
         </div>
      </div>
   </div>
</section>

Step 2: 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");
body {
  background-color: #2e2e2e;
  font-family: "IBM Plex Sans", sans-serif;
  margin: 0;
}

#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%;
  }
}

/* Tabs menu */
.tabs {
  margin: 0;
  background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
  border-radius: 2px 2px 0px 0px;
}
@media screen and (max-width: 512px) {
  .tabs {
    height: 40px;
  }
}

/* Tab Links */
.tablinks {
  background: transparent;
  background-image: linear-gradient(90deg, transparent 70%, rgba(255, 255, 255, 0.2) 100%);
  border: none;
  outline: none;
  cursor: pointer;
  width: 25%;
  /*change depending on the number of tabs*/
  height: 80px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  font-family: "IBM Plex Sans", sans-serif;
  overflow: hidden;
  transition: 0.3s ease;
}
@media screen and (max-width: 512px) {
  .tablinks {
    height: 40px;
    font-size: 12px;
  }
}

.tablinks:before {
  background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  content: "";
  width: 100%;
  height: 0px;
  position: absolute;
  top: 0;
  left: 0;
  transition: 0.3s ease-in-out;
  z-index: 2;
}

/*tab buttons hover*/
.tablinks:hover::before {
  height: 100%;
  z-index: 2;
  bottom: 0;
}
@media screen and (max-width: 512px) {
  .tablinks:hover::before {
    height: 0;
  }
}

/* Tab active */
.tablinks.active {
  background-color: white;
  z-index: 0;
  border-right: 0px;
  border-left: 0px;
  height: 110px;
  bottom: 0px;
  overflow: hidden;
}
@media screen and (max-width: 512px) {
  .tablinks.active {
    height: 60px;
  }
}

.tablinks.active:before {
  content: "";
  width: 100%;
  height: 5px;
  top: 0;
  left: 0;
}

/* Tabs text */
.tablinks.active p,
.tablinks.active:hover p {
  opacity: 1;
  background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tablinks p {
  z-index: 2;
  opacity: 0.6;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: 0.5s ease;
  padding: 0;
  margin: 0;
  color: #686868;
  backface-visibility: hidden;
  font-weight: 400;
}

.tablinks:hover p {
  color: white;
  opacity: 1;
}
@media screen and (max-width: 512px) {
  .tablinks:hover p {
    color: #686868;
    opacity: 0.6;
  }
}

/* Tabs text bigger */
.tablinks p:before {
  content: attr(data-title);
  position: absolute;
  height: auto;
  width: auto;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.1;
  font-size: 40px;
  transition: 1s ease-out;
  z-index: -1;
  font-weight: 600;
  top: 110%;
}
@media screen and (max-width: 512px) {
  .tablinks p:before {
    display: none;
  }
}

.tablinks:hover p:before {
  opacity: 0.1;
  font-size: 40px;
  top: -80%;
}

/* tab content */
.wrapper_tabcontent {
  background-color: white;
  margin-top: 0px;
  z-index: -3;
  position: relative;
  opacity: 1;
  padding: 40px 60px;
  overflow: hidden;
  transition: all 1s ease;
  top: 0;
}

.tabcontent {
  display: none;
  min-height: 180px;
}

@keyframes tabEffect {
  from {
    top: -40px;
  }
  to {
    top: 0px;
  }
}
.tabcontent.active {
  transition: all 1s ease;
  display: block;
}

/* Tab content line */
.wrapper_tabcontent:after {
  content: "";
  height: 5px;
  width: 100%;
  position: absolute;
  background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  left: 0;
  bottom: 0;
  z-index: -2;
  transition: all 1s ease;
}

/* Title */
.tabcontent h3 {
  font-size: 40px;
  top: 75px;
  transform: rotate(90deg);
  position: absolute;
  left: -90px;
  opacity: 0.1;
  width: 200px;
  height: 60px;
  background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 0;
  animation: city 1s ease;
}
@media screen and (max-width: 512px) {
  .tabcontent h3 {
    top: 65px;
  }
}

@keyframes city {
  from {
    left: -150px;
  }
  to {
    left: -90px;
  }
}
/* Text*/
.tabcontent p {
  color: #686868;
  margin: 0;
  padding: 0;
  line-height: 28px;
  font-weight: 100;
  transition: all 1s ease;
  animation: fadeEffect 0.6s ease;
  width: 100%;
  font-size: 16px;
  font-family: "IBM Plex Sans", sans-serif;
}
@media screen and (max-width: 512px) {
  .tabcontent p {
    font-size: 14px;
    line-height: 26px;
  }
}

@keyframes fadeEffect {
  from {
    opacity: 0;
    margin-left: 30px;
  }
  to {
    opacity: 1;
    margin-left: 0;
  }
}

 Step 3: JS:

// 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");
}