css Responsive menu

 Html:---

<link rel="stylesheet" href="style/menuresp.css">

</head>

<body>
    <div class="container">
        <div class="header">
            <div class="title">
                <h1>Premium</h1>
            </div>
            <!-- adding responsiveness -->
            <a href="#" class="togglebutton">
                <span class="bar"></span>
                <span class="bar"></span>
                <span class="bar"></span>
            </a>
            <!------>



            <div class="menu">
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Contact</a></li>
                    <li><a href="#">Profile</a></li>
                </ul>
            </div>
        </div>
    </div>
    <script src="script/respmenu.js"></script>
</body>

</html>

css:--

* {
    margin0px;
    padding0px;
    box-sizingborder-box;
}

.container {
    height100vh;
    width100vw;
    background-coloraqua;
}

.header {
    width100vw;
    /* height: 20vh; */
    background-colorblue;
    displayflex;
    justify-contentspace-between;
    align-itemscenter;
    colorwhite;
}

.title {
    width30vw;
    /* height: 20vh; */
    background-colorburlywood;
}

.menu {
    width50vw;
    /* height: 20vh; */
    background-colorcadetblue;
}

.menu ul {
    displayflex;
}

.menu li {
    list-style-typenone;
}

.menu li a {
    text-decorationnone;
    colorwhite;
    padding1em;
    displayblock;
    /*larger in size*/
}

.menu li :hover {
    background-colorgrey;
}

.togglebutton {
    positionabsolute;
    /*right side 
of the element */
    top.75rem;
    right1rem;
    /* display: flex; */
    displaynone;
    flex-directioncolumn;
    justify-contentspace-between;
    width30px;
    height21px;
    /* background-color: red; */
}

.togglebutton .bar {
    height5px;
    width100%;
    background-colorwhite;
    border-radius10px;
    /* background-color: white; */
    /* border-radius:20px; */
}



@media screen and (max-width:576px) {
    .header {
        background-colorgold;
        flex-directioncolumn;

    }

    .title {
        background-colorgreenyellow;
        width100vw;

    }

    .menu {
        background-colorhotpink;
        width100vw;

    }

    .togglebutton {
        displayflex;
    }

    .menu {
        flex-directioncolumn;
        align-itemsflex-start;
        displaynone;
        width100%;
    }

    .menu ul {
        flex-directioncolumn;
        width100%;
    }

    .menu li {
        text-aligncenter;
    }

    .menu li a {
        padding.5rem 1rem;
    }

    .menu.active {
        displayflex;
    }



}

js:--

const togglebutton = document.
getElementsByClassName('togglebutton')[0];
const menu = document.getElementsByClassName
('menu')[0];
togglebutton.addEventListener('click', () =>
 {
    menu.classList.toggle('active')
})

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation