Skip to content
Advertisements

CSS Search Box


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">
</head>
<body>
    
    <div class="search">
        <input type="text" name="" placeholder="Search">
        <div class="icon"></div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".icon").click(function(){
                $(".search").toggleClass("active")
            })
        })
    </script>

</body>
</html>

CSS CODE:

body{
    margin:0;
    bottom: 0;
    background:url(https://images7.alphacoders.com/375/375724.jpg);
    background-size: cover;background-repeat: no-repeat;
  width:100vh;
  height:100vh;
}
.search{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 80px;
    height: 80px;
    background: #fff;
    box-shadow: 0 5px 20px rgba(0,0,0,.5);
    border-radius: 4px;
    transition: .5s;
    overflow: hidden;
}
.search.active{
    width: 600px;
}
.search input{
    position: absolute;
    top: 10px;
    left: 10px;
    width: calc(100% - 90px);
    height: 60px;
    border:none;
    outline: none;
    font-size: 36px;
    padding: 0 10px;
    color: #666;
}
.icon {
    position: absolute;
    width: 60px;
    height: 60px;
    background:#fff;    
    top: 10px;
    right: 10px;
    cursor: pointer;
    transition: .5s;
    border-radius: 4px;
}
.search.active .icon{
    background: #ff355a;
}
.search.active .icon:before{
    content: "";
    position: absolute;
    top:20px;
    left: 15px;
    width: 18px;
    height: 35px;
    background: transparent;
    border:none;
    border-right:2px solid #fff;
    border-radius: 0;
    transition: .5s;
    transform: rotate(-45deg);
}
.search.active .icon:after{
    content: "";
    position: absolute;
    top:10px;
    left: 13px;
    width: 18px;
    height: 35px;
    background: transparent;
    border:none;
    border-right:2px solid #fff;
    border-radius: 0;
    transition: .5s;
    transform: rotate(45deg);
}
.icon:before{
    content: "";
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    background:transparent;
    border:2px solid #262626;
    border-radius: 50%;
    transition: .5s;
}
.icon:after{
    content: "";
    position: absolute;
    top: 25px;
    left: 35px;
    width: 18px;
    height: 18px;
    background:transparent;
    border-left:2px solid #262626;
    transform: rotate(-45deg);
    transition: .5s;
}
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: