Animated Search Bar HTML CSS Jquery Code

HTML CODE:




<!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="style.css"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>
<body>

    <div class="wrapper">
        <div class="searchbar">
            <input type="text" placeholder="search items ,brands & products here....." class="input">
        </div>
        <div class="btn">

            <i class="fa fa-search" aria-hidden="true"></i>


        </div>
    </div>

    <script>
        $(document).ready(function(){
        $(".btn").click(function(){
        
      $(".input").toggleClass("active").focus;

        });



        });
    </script>
    
</body>
</html>



CSS CODE:



*{
    margin: 0;
    padding: 0;
    user-select: none;
}


body{
    background-color: palevioletred;
}

.wrapper{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);

}

.input{
    position: relative;
    width: 0px;
    height: 50px;
    border: solid 3px red;
    border-radius: 50px;
    outline: none;
    padding: 0px 10px;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 30%;
    transition: all 0.8s ease;
    
}
.btn{
    position: absolute;
    top: 0%;
    left:74%;
    transform: translate(-50%,-50%);
    width: 60px;
    height: 60px;
    border: solid 3px palevioletred;
    border-radius: 60px;
    background-color: rgb(250, 2, 2);
    line-height: 60px;
    text-align: center;
   font-size: 30px;
   color: rgb(255, 255, 255);
   transition: all 0.8s ease;
}
.active{
    width: 350px;   
}

























Post a Comment

0 Comments