Skip to main content

Responsive Nav Bar

 Responsive Nav Bar 

review of navbar












Font Awsome cdn link

 <script src="https://kit.fontawesome.com/6d985e968b.js"
 crossorigin="anonymous"></script>

CSS

<style>
            *{
                padding0;
                margin0;
                list-style: none;
                box-sizing: border-box;
            }
            .navbar{
                width100%;
                height50px;
                background-color:#000;
                
                

            }
            .logo{
                color:#fff;
                width200px;
                float: left;
                font-size30px;cursor: pointer;
                margin-left50px;
                line-height40px;
                
            }
            .navbar ul{
                margin-right50px;
                float: right;
                line-height40px;
               
            
            }
            .navbar ul li{
                display: inline-block;
                margin10px 10px;
            }
            .navbar ul li a{
                text-decoration: none;
                color: #fff;


            }
            .active a:hover{
                background-color: blue;
            }
            .toggler{
                color: #fff;
                float:right;
                margin-right:50px;
                margin-top10px;
                display: none;
                cursor: pointer;
            }
            .cut{
                cursor: pointer;
                display:none;
            }
            @media (max-width768px){
                .logo{
                    font-size:20px;
                    margin-left10px;
                    margin-top:10px;
                }
                .toggler{
                    display:block;
                }
                .navbar ul{
                  position:fixed;
                  top:50px;
                  left:-100%;
                    width100%;
                    height:100vh;
                    background-color:greenyellow;
                    margin-right0;
                    text-align: center;
                    transition: all,0.5s;
                }
               .navbar ul li{
                    display:block;
                }
                .navbar ul li a{
                    font-size:20px;
                }
                .cut{
                    display:block;
                    position: absolute;
                    top:10px;
                    right:20px;
                }

            }


        </style>

HTML


<nav class="navbar">

            <div class="logo">DesignX</div>
            <div class="toggler"><i class="fas fa-bars"></i></div>
            <ul>
              <div class="cut"><i class="fas fa-times"></i></div>  
                <li class="active"><a href="">Home</a></li>
                <li><a href="">About</a></li>
                <li><a href="">Contact</a></li>
                <li><a href="">More</a></li>
            </ul>
            
        </nav>

JS

<script type="text/javascript">
        let responsive = document.querySelector('ul');
        let toggler = document.querySelector('.toggler');
        let cancel = document.querySelector('.cut')

        toggler.addEventListener('click',()=>{
            
            responsive.style.left = 0;

        })
        cancel.addEventListener('click',()=>{
            responsive.style.left ='-100%';
        })


        </script>

Comments