I am tring to make a glass effect in navbar of my website. Here is the code:
HTML:
<nav class="navbar">
<div class="logo">
<a href="#">Logo</a>
</div>
<div class="mobile_nav">
<i class="fa-solid fa-bars"></i>
</div>
<menu class="menu">
<a href="#">Home</a>
<a href="#pricing">Pricing</a>
<a href="#about">About</a>
<a href="#contact">Get in Touch</a>
</menu>
</nav>
CSS:
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap');
:root{
--black: #0f0f19;
--gray: #7a7b7f;
--light-gray: #ddd;
--primary: #0da87c;
--white: #fff;
}
*{
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
box-sizing: border-box;
}
a{
text-decoration: none;
color:var(--black);
}
.navbar{
width:100vw;
width: calc(100vw - 100px);
margin-left: 50px;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
background: #e2e2e2a6;
display:flex;
justify-content:space-evenly;
height:70px;
line-height: 70px;
position:fixed;
top: 0;
left: 0;
z-index: 99;
backdrop-filter: blur(5px);
}
.navbar a{
padding: 5px 10px;
color: var(--gray);
font-size: 14px;
font-weight: bold;
transition: all .25s ease-in-out;
}
.navbar menu a:hover{
color: var(--black);
}
.mobile_nav{
display: none;
}
.navbar + *{
margin-top:70px;
}
@media screen and (max-width: 768px) {
.mobile_nav{
display: block;
position: fixed;
right: 24px;
}
.navbar menu{
width: calc(100% - 20px);
margin: 0 10px;
position: fixed;
left: 0;
bottom: -50%;
display: flex;
flex-direction: column;
background-color: #333;
line-height: 30px;
border-radius: 30px 30px 0 0;
padding: 10px;
transition: bottom .25s ease-in-out;
}
.mobile_nav{
font-size: 24px;
}
.active{
bottom: 0 !important;
}
}
If you try to view the above code on a mobile screen, you will notice that when you click on the hamburger icon the menu should come from the bottom of the screen but when I add backdrop-filter: unset;
to the .navbar
class, it is working fine but when I add this, it removes the glass effect.
I'm trying to add the glass effect on both desktop and mobile screens with position: fixed on the inner tag. Help me out please!