Home > OS >  Changing the side menu from open to closed
Changing the side menu from open to closed

Time:12-26

my Hamburger menu is normaly open ,when i click an the Hamburger menu, it will be close. I want exactly the opposite. I want to side menu be close normaly and when i click on it, it be open.

Codepen

I tried to make it with Js but i'm really amature and i hope learn from you guys. Thank you

[Codepen](https://codepen.io/MG-/pen/PoBPzQo)

CodePudding user response:

Add "collapse" to the "wrapper" class.

example:

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&display=swap');

*{
    margin: 0;
    list-style: none;
    padding: 0;
    box-sizing: border-box;
    text-decoration: none;
    font-family: 'Montserrat', sans-serif;

}

body{
    background-color: rgb(229, 233, 233);
}
.wrapper{
    margin: 10px;
}
.wrapper .top_navbar{
    display: flex;
    position: fixed;
    width: calc(100% - 20px);
    height: 60px;
    top: 10px;
    
}
.wrapper .top_navbar .hamburger{
    width: 70px;
    height: 100%;
    background-color: #0438ae;
    padding: 15px, 17px;
    border-radius: 20px 0 0 0;
    cursor: pointer;
    border-right: 1px solid;
    border-image: linear-gradient(to top,rgb(221, 220, 220) 40%, transparent 60%) 1 100%; 
}
.wrapper .top_navbar .hamburger div{
    width: 35px;
    height: 4px;
    background-color: white;
    align-items: center;
    margin: 5px 0;
    position: relative;
    top: 15.5px;
    left: 17.5px
}
#d2{
    width: 25px;
    height: 4px;
    margin-left: 10px;
    
}
#d3{
    width: 18px;
}
.wrapper .top_menu{
    width: calc(100% - 70px);
    background-color: white;
    height: 100%;
    border-radius: 0 20px 0 0;
}
.wrapper .top_menu .logo{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    
}
.logo img{
    width: 150px;
    height: 60px;
}
.wrapper .top_menu ul{
    display: flex;
}
.wrapper .top_menu ul li a{
    display: block;
    margin: 0 10px;
    color: #0438ae;
    width: 40px;
    height: 40px;
    border: #fff 1px solid;
    border-radius: 50%;
    text-align: center;
    align-content: center;
    line-height: 40px;
}
.wrapper .top_menu ul li a:hover{
    opacity: 70%;
    transition: 0.75s;
    box-shadow: 0 0 35px rgba(77, 79, 190, 0.452);
    border: 1px solid rgba(128, 128, 128, 0.445);
    
}
.wrapper .sidebar{
    position: fixed;
    top: 70px;
    left: 10px;
    width: 200px;
    height: calc(100% - 80px);
    background-color: #0438ae;
    border-radius: 0 0 0 20px;
    transition: all 0.3s ease;
        
}

.wrapper .sidebar:before{
    width: 75px;
    position: absolute;
    content: "";
    display: none;
}

.wrapper .sidebar ul li a{
    display: block;
    padding: 30px 20px;
    color: #fff;
    position: relative;
    margin-bottom: 1px;
    top: 50px;
    white-space: nowrap;
    
}
.wrapper .sidebar ul li a:before{
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #0438ae;
    display: none;
}
.wrapper .sidebar ul li a span.icon{
    margin-right: 10px;
    display: inline-block;
    justify-content: center;
}
.wrapper .sidebar ul li a span.title{
    display: inline-block;
}

.wrapper .sidebar ul li a:hover,
.wrapper .sidebar ul li a.active{
    background: #4360b5;
    color: #fff;
    transition: 0.55s ease-out;
}


.wrapper .sidebar ul li a:hover:before,
.wrapper .sidebar ul li a.active:before{
    display: block;
}

.wrapper .main_container{
    width: calc(100% - 200px);
    margin: 100px 0 0 200px;
    padding: 25px;
    transition: all 0.3s ease;
}

.wrapper .main_container .item{
    padding: 15px;
    background: white;
    margin-bottom: 15px;
    line-height: 22px;
}

.wrapper.collapse .sidebar{
    width: 70px;
    
}

.wrapper.collapse .sidebar ul li a{
    text-align: center;
}

.wrapper.collapse .sidebar ul li a span.icon{
    margin: 0;
}

.wrapper.collapse .sidebar ul li a span.title{
    display: none;
}

.wrapper.collapse .main_container{
    width: calc(100% - 70px);
    margin-left: 70px;
}
/* Test Profil*/

.profile{
    position: absolute;
    top: 55px ;
    right: 0px;
    background-color: #fff;
    width: 180px;
    padding: 10px 0;
    box-shadow: 0 0 2px rgb(0,0,0,0.5);
    border-radius: 3px;
    user-select: none;
    display: none;
}

.profile .profile_item{
    padding: 10px;
    cursor: #0438ae;
    cursor: pointer;
}

.profile .profile_item:hover{
    color: white;
    background-color: #4360b5;
    transition: all 0.35s ease-in;
}
.profile:before{
    content: "";
    position: absolute;
    top: -21px;
    left: 60px;
    border: 10px solid;
    border-color: transparent transparent rgb(236, 235, 235) transparent;
    
}

.profile.active{
    display: block;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Real State Dashboard</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
    <script src="https://kit.fontawesome.com/b86172c06f.js" crossorigin="anonymous"></script>
</head>
<body>
    <div >
        <div >
            <div >
                <div></div>
                <div id="d2"></div>
                <div id="d3"></div>
            </div>
            <div >
                <div ><a href="#">
                    <img src="./src/Property Real Estate logo.jpg" alt="">
                </a>
                    <ul>
                        <li><a href="#"><i ></i></a></li>
                        <li><a href="#"><i ></i></a>
                            <div >
                                <div >Pofile</div>
                                <div >Change Password</div>
                                <div >Logout</div>
                            </div>
                        </li>
                        <li><a href="#"><i ></i></a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div >
            <ul>
                <li><a href="#">
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
                <li><a href="#">
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
                <li><a href="#">
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
                <li><a href="#">
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
                <li><a href="#" >
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
                <li><a href="#">
                    <span >
                        <i ></i>
                    </span>
                    <span >Books</span>
                </a></li>
            </ul>
        </div>
        <div >
            <div >
                Lorem ipsum, dolor sit amet consectetur adipisicing elit. A necessitatibus minus et adipisci pariatur dolorum commodi sed. Libero, ratione repellendus. Tempore vel tenetur fugit nesciunt labore in eos reiciendis molestias?
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function(){
            $(".hamburger").click(function(){
               $(".wrapper").toggleClass("collapse");
                  
            });
            
        });
        $(document).ready(function(){
            $(".fas").click(function(){
                $(".profile").toggleClass("active");
            });
        })
    </script>
</body>
</html>

  • Related