Posted on • Updated on

Mobile navigation with backdrop blur effect

author

Kai

In this tutorial, I'll show you how to make Mobile/Sidebar Navigation with a backdrop blur effect without using any third-party resources.

#index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./main.css">
</head>
<body>
    <div class="container">
        <header>
            <nav>
                <div class="logo">
                    Logo
                </div>
                <button id="open">
                    menu
                </button>
            </nav>
        </header>
        <div class="hero">
            <h1>
                I'm <br> 
                Hero...  
            </h1>
        </div>
    </div>
    <div class="sidebar">
        <nav>
            <button id="close">close</button>
        </nav>
        <div class="nav-link-wrapper">
            <a href="#" class="nav-link">home</a>
            <a href="#" class="nav-link">class</a>
            <a href="#" class="nav-link">jobs</a>
            <a href="#" class="nav-link">list</a>
            <a href="#" class="nav-link">about</a>
        </div>
    </div>
    <script src="./main.js"></script>
</body>
</html>

#main.css

body {
  margin: 0;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
}

.container {
  height: 100vh;
}

header {
  padding: 1em;
}

header nav {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
      -ms-flex-pack: justify;
          justify-content: space-between;
}

.hero {
  padding: 1em;
  font-size: 2rem;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  height: 80%;
}

.sidebar {
  background-color: turquoise;
  width: 0px;
  height: 100%;
  position: fixed;
  top: 0;
  right: 0;
  z-index: 100;
}

.sidebar nav {
  padding: 1em;
  height: 20%;
}

.sidebar .nav-link-wrapper {
  padding: 1em;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

.sidebar .nav-link-wrapper .nav-link {
  margin: 1em 0;
  list-style: none;
  display: block;
  text-align: center;
  color: #0e0e0e;
  text-decoration: none;
  text-transform: capitalize;
  font-size: 2rem;
}

.sidebar .nav-link-wrapper .nav-link:hover {
  text-decoration: underline;
}

#main.js

var open = document.querySelector('#open');
var close = document.querySelector('#close');
var sidebar = document.querySelector('.sidebar');
var container = document.querySelector('.container');

open.addEventListener('click',()=>{
    sidebar.style.width = '240px';
    sidebar.style.transition = '0.3s';
    container.style.transition = '0.3s';
    container.style.filter = 'blur(2px)';

});
close.addEventListener('click',()=>{
    sidebar.style.width = '0px';
    container.style.filter = 'blur(0px)';
});

#OUTPUT

//nav close

//nav open

end of article

Related Posts

Join Our Newsletter

Want the latest & greatest from our blog straight to your inbox with some exclusive offers from our partners and sponsors?

We won't spam. Promise.