abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/14/2020

How to create vertical tabs using CSS and JAVASCRIPT

 <html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

* {box-sizing: border-box}

body {font-family: "Lato", sans-serif;}


/* Style the mytab */

.mytab {

  float: left;

  border: 1px solid #ccc;

  background-color: #f1f1f1;

  width: 30%;

  height: 300px;

}


/* Style the buttons inside the mytab */

.mytab button {

  display: block;

  background-color: inherit;

  color: black;

  padding: 22px 16px;

  width: 100%;

  border: none;

  outline: none;

  text-align: left;

  cursor: pointer;

  transition: 0.3s;

  font-size: 17px;

}


/* Change background color of buttons on hover */

.mytab button:hover {

  background-color: #ddd;

}


/* Create an active/current "mytab button" class */

.mytab button.active {

  background-color: #ccc;

}


/* Style the mytab content */

.mytabcontent {

  float: left;

  padding: 0px 12px;

  border: 1px solid #ccc;

  width: 70%;

  border-left: none;

  height: 300px;

}

</style>

</head>

<body>


<h2>Vertical mytabs</h2>

<p>Click on the buttons inside the mytabbed menu:</p>


<div class="mytab">

  <button class="mytablinks" onclick="openCity(event, 'India')" id="defaultOpen">India</button>

  <button class="mytablinks" onclick="openCity(event, 'America')">America</button>

  <button class="mytablinks" onclick="openCity(event, 'Africa')">Africa</button>

</div>


<div id="India" class="mytabcontent">

  <h3>India</h3>

  <p>India is the capital city of England.</p>

</div>


<div id="America" class="mytabcontent">

  <h3>America</h3>

  <p>America is the capital of France.</p> 

</div>


<div id="Africa" class="mytabcontent">

  <h3>Africa</h3>

  <p>Africa is the capital of Japan.</p>

</div>


<script>

function openCity(evt, cityName) {

  var i, mytabcontent, mytablinks;

  mytabcontent = document.getElementsByClassName("mytabcontent");

  for (i = 0; i < mytabcontent.length; i++) {

    mytabcontent[i].style.display = "none";

  }

  mytablinks = document.getElementsByClassName("mytablinks");

  for (i = 0; i < mytablinks.length; i++) {

    mytablinks[i].className = mytablinks[i].className.replace(" active", "");

  }

  document.getElementById(cityName).style.display = "block";

  evt.currentTarget.className += " active";

}


// Get the element with id="defaultOpen" and click on it

document.getElementById("defaultOpen").click();

</script>

   

</body>

</html> 


No comments:

Post a Comment

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...