Responsive Multi-tab Card Design using HTML, CSS & JavaScript

Responsive Multi-tab Card Design using HTML, CSS & JavaScript


Hello developers, today in this blog you’ll learn to create a Responsive Multi-tab Card Design using HTML, CSS & JavaScript.

Multi-tab is a great way to present the content to the viewers. Multi-tab is used to save the space of the website.

In this program (Responsive Multi-tab Card Design), on the webpage, there are five tabs with labels. Those labels are named Item1, Item2, and so on. You can create many tabs as much as you need. When the user clicks on the labels, the respective tab with its content will be displayed. JavaScript code is used to move from one tab to the other tabs on clicking the label.

The source code of this Responsive Multi-tab Card Design using HTML, CSS & JavaScript is given below, if you want the source code of this program, you can copy it. You can use this Responsive Multi-tab Card Design using HTML, CSS & JavaScript on your projects.

Responsive Multi-tab Card Design using HTML, CSS & JavaScript [Source Code]

To make this website (Responsive Multi-tab Card Design), you need to create three files: an HTML file, a CSS file, and a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>JS Multitab Card || learningrobo</title> <link rel="stylesheet" href="style.css"> </head> <body> <section class="container"> <ul class="tabs"> <li class="tab-item"><a href="#item1" class="active">Item 1</a></li> <li class="tab-item"><a href="#item2">Item 2</a></li> <li class="tab-item"><a href="#item3">Item 3</a></li> <li class="tab-item"><a href="#item4">Item 4</a></li> <li class="tab-item"><a href="#item5">Item 5</a></li> </ul> <div class="wrapper_tab-content"> <article id="item1" class="tab-content content-visible"> <h1>Item One</h1> <p> Roof party irony iceland, ugh sartorial banh mi photo booth semiotics lyft williamsburg before they sold out celiac chambray wolf tumeric. Gastropub typewriter sustainable man bun hoodie. </p> </article> <article id="item2" class="tab-content"> <h1>Item Two</h1> <p> Roof party irony iceland, ugh sartorial banh mi photo booth semiotics lyft williamsburg before they sold out celiac chambray wolf tumeric. Gastropub typewriter sustainable man bun hoodie. </p> </article> <article id="item3" class="tab-content"> <h1>Item Three</h1> <p> Roof party irony iceland, ugh sartorial banh mi photo booth semiotics lyft williamsburg before they sold out celiac chambray wolf tumeric. Gastropub typewriter sustainable man bun hoodie. </p> </article> <article id="item4" class="tab-content"> <h1>Item Four</h1> <p> Roof party irony iceland, ugh sartorial banh mi photo booth semiotics lyft williamsburg before they sold out celiac chambray wolf tumeric. Gastropub typewriter sustainable man bun hoodie. </p> </article> <article id="item5" class="tab-content"> <h1>Item Five</h1> <p> Roof party irony iceland, ugh sartorial banh mi photo booth semiotics lyft williamsburg before they sold out celiac chambray wolf tumeric. Gastropub typewriter sustainable man bun hoodie. </p> </article> </div> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> </section> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and, remember that you have to create a file with a .css extension.


@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400;600&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  color: inherit;
}

body {
  font-family: 'Poppins', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #85FFBD;
background-image: linear-gradient(45deg, #85FFBD 0%, #FFFB7D 100%);

}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;
  height: 30px;
}

.container {
  max-width: 700px;
  width: 100%;
  background-color: #12192c;
  padding: 30px;
  border-radius: 20px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
} 

li a {
  color: #fff;
}

li a:hover {
  padding-bottom: 4px;
  border-bottom: 3px solid #85FFBD;
}

.wrapper_tab-content {
  position: relative;
}

.tab-content {
  position: absolute;
  padding: 1.75em 0;
  visibility: hidden;
  height: 0;
  color:#fff
}

.tab-content h1 {
  font-size: 1.12em;
  margin-bottom: .5em;
}

.content-visible {
  position: static;
  visibility: visible;
  height: auto;
}

.active {
  color: #85FFBD;
  padding-bottom: 4px;
  border-bottom: 3px solid #85FFBD;
}

.credit a{
  text-decoration: none;
  color: #85FFBD;
  font-weight: 800;
  }
  
  .credit {
      text-align: center;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    margin: 10px;
    color:#FFF
  }
JavaScript makes the page work functionally. At last, create a JavaScript file with the name of script.js and remember that you've got need to make a file with a .js extension.


const selectTab = element => {
  const active = document.querySelector('.active');
  const visible = document.querySelector('.content-visible');
  const tabContent = document.getElementById(element.href.split('#')[1]);
  if (active) {
    active.classList.remove('active');
  }
  element.classList.add('active');
  if (visible) {
    visible.classList.remove('content-visible');
  }
  tabContent.classList.add('content-visible');
}
document.addEventListener('click', event => {
  if (event.target.matches('.tab-item a')) {
    selectTab(event.target);
  }
}, false);
We hope you would like this Responsive Multi-tab Card Design using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem in creating this Responsive Multi-tab Card Design using HTML, CSS & JavaScript, then contact us or comment us. We’ll try to provide a solution to your problem as soon as possible.

Thank you
Learning robo team

إرسال تعليق

Thank you
Learning robo team

Post a Comment (0)

أحدث أقدم
Learning Robo says...
code copied
Welcome