How To Create Glassmorphism Close And Fade In Tabs In Website Using Html, Css, Js
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="tabs">
<h2>Tabs</h2>
<p>Click on the x button in the top right corner to close the current tab:</p>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<span onclick="this.parentElement.style.display='none'" class="topright">×</span>
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
</div>
<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[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>
CSS
body {
margin: 0;
padding: 0;
font-family: Arial;
background: linear-gradient(rgba(0, 0, 0, 0.5),rgba(0, 0, 0, 0.5)), url(/2.bmp);
background-size: cover;
overflow:hidden;
}
.tabs{
width: 50%;
margin: 15% 25%;
border-radius: 20px;
}
/* Style the tab */
.tab {
overflow: hidden;
background-color: rgb(255, 255, 255,0.1);
backdrop-filter: blur(30px);
border-radius: 20px;
}
.tabs h2, p{
color: white;
}
/* Style the buttons inside the tab */
.tab button {
color: white;
float: left;
border: none;
outline: none;
transition: 0.3s ease-in;
border-radius: 20px;
cursor: pointer;
padding: 16px;
font-size: 17px;
background-color: rgb(255, 255, 255,0.1);
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(60px);
}
/* Create an active/current tablink class */
.tab button.active{
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(60px);
}
/* Style the tab content */
.tabcontent {
background-color: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(30px);
display: none;
padding: 6px 12px;
border-top: none;
border-radius: 20px;
color: white;
-webkit-animation: fadeEffect 3s;
animation: fadeEffect 3s;
}
/* Style the close button */
.topright {
float: right;
cursor: pointer;
font-size: 28px;
}
.topright:hover {color: red;}
/* Fade in tabs */
@-webkit-keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeEffect {
from {opacity: 0;}
to {opacity: 1;}
}
No comments:
Post a Comment