Skip to content
Advertisements

CSS Hamburger Button

HTML CODE:

<!DOCTYPE html>
<html>
<head>
    <title>page</title>
     <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="1.page.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
    <script
      src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".icon").click(function(){
                $(".icon").toggleClass("active");
            })
        })
    </script>
</head>
<body>

    <div class="icon">
        <div class="hamburger"></div>
    </div>

</body>
</html>

CSS CODE:

body{
    margin: 0;
    padding: 0;
    background: #ff4c40;
}
.icon{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 400px;
    height: 400px;
    cursor: pointer;
}
.hamburger{
    width: 250px;
    height: 30px;
    background: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    box-shadow: 0 10px 50px rgba(0,0,0,.2);
    transition: .5s;
}
.hamburger:before,
.hamburger:after{
    content: "";
    position: absolute;
    width: 250px;
    height: 30px;
    background:#fff;
    box-shadow: 0 2px 5px rgba(0,0,0,.2);
    transition: .5s;
}
.hamburger:before{
    top: -80px;
}
.hamburger:after{
    top: 80px;
}
.icon.active .hamburger{
    background: rgba(0,0,0,0);
    box-shadow: 0 2px 5px rgba(0,0,0,0);
}
.icon.active .hamburger:before{
    top: 0;
    transform: rotate(45deg);
}
.icon.active .hamburger:after{
    top: 0;
    transform: rotate(135deg);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: