<!DOCTYPE html>
<html>
<head>
<title>Membuat Tab Gudang Coding</title>
</head>
<style>
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #33FFF2;
}
/* Style tombol yang digunakan untuk membuka konten tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
}
/* Ubah warna latar belakang tombol saat mengarahkan kursor */
.tab button:hover {
background-color: #43FF33;
}
/* Buat kelas tablink aktif / saat ini */
.tab button.active {
background-color: #FF3333;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
.tabcontent {
animation: fadeEffect 1s; /* Fading effect takes 1 second */
}
/* Go from zero to full opacity */
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
/* Style the close button */
.topright {
float: right;
cursor: pointer;
font-size: 28px;
}
</style>
<body>
<!-- Tab links -->
<div class="tab">
<button class="tablinks" onclick="openCity(event, \'Surabaya\')">Surabaya</button>
<button class="tablinks" onclick="openCity(event, \'Jakarta\')">Jakarta</button>
<button class="tablinks" onclick="openCity(event, \'Bali\')">Bali</button>
</div>
<!-- Tab content -->
<div id="Surabaya" class="tabcontent">
<span onclick="this.parentElement.style.display=\'none\'" class="topright">×</span>
<h3>Surabaya</h3>
<p>Kota Surabaya adalah ibu kota Provinsi Jawa Timur, Indonesia,</p>
</div>
<div id="Jakarta" class="tabcontent">
<h3>Jakarta</h3>
<p>Daerah Khusus Ibukota Jakarta adalah ibu kota negara dan kota terbesar di Indonesia</p>
</div>
<div id="Bali" class="tabcontent">
<h3>BALI</h3>
<p>Bali adalah sebuah pulau di Indonesia yang dikenal karena memiliki terumbu karang yang cantik.</p>
</div>
<script>
function openCity(evt, cityName) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
</body>
</html>