Search Bar Using Html CSS & javascript | CSS Expandable Search Box

HTML
<div class="search">
    <div class="icon"></div>
    <div class="input">
        <input type="text" placeholder="Search" id="mysearch">
    </div>
    <span class="clear" onclick="document.getElementById('mysearch').value=''"></span>
</div>
CSS
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500&display=swap');

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:'Poppins',sans-serif;
}
body
{
    display:flex;
    justify-content:center;
    align-items:center;
    min-height:100vh;
    background:#297eff;
}
.search
{
    position:relative;
    width:60px;
    height:60px;
    background:#fff;
    border-radius:60px;
    transition:0.5s;
    box-shadow:0 0 0 5px #2573ef;
    overflow:hidden;
}
.search.active
{
    width:360px;
}
.search .icon
{
    position:absolute;
    top:0;
    left:0;
    width:60px;
    height:60px;
    background:#fff;
    border-radius:60px;
    display:flex;
    justify-content:center;
    align-items:center;
    z-index:1000;
    cursor:pointer;
}
.search .icon::before
{
    content:'';
    position:absolute;
    width:15px;
    height:15px;
    border:3px solid #287dfc;
    border-radius:50%;
    transform:translate(-4px,-4px);
}
.search .icon::after
{
    content:'';
    position:absolute;
    width:3px;
    height:12px;
    background:#287dfc;
    transform:translate(6px,6px) rotate(315deg);
}
.search .input
{
    position:relative;
    width:300px;
    height:60px;
    left:60px;
    display:flex;
    justify-content:center;
    align-items:center;
}
.search .input input
{
    position:absolute;
    top:0;
    width:100%;
    height:100%;
    border:none;
    outline:none;
    font-size:18px;
    padding:10px 0;
}
.clear
{
    position:absolute;
    top:50%;
    transform:translateY(-50%);
    width:15px;
    height:15px;
    right:15px;
    cursor:pointer;
    display:flex;
    justify-content:center;
    align-items:center;
    
}
.clear::before
{
    position:absolute;
    content:'';
    width:1px;
    height:15px;
    background:#999;
    transform:rotate(45deg);
}
.clear::after
{
    position:absolute;
    content:'';
    width:1px;
    height:15px;
    background:#999;
    transform:rotate(315deg);
}
JS
const icon  = document.querySelector('.icon');
const search= document.querySelector('.search');

icon.onclick = function(){
    search.classList.toggle('active');
}

/*
    Fuente: https://www.youtube.com/watch?v=RctaFustg5w
    Todo los creditos a sus autor
*/

Autor: Web322

Publicado: 23/07/2021

Compartir Elemento Web

Donar a Compositu
Otras formas de ayudar
  • Compártelo en tus redes sociales.
  • Recomienda los elementos.
  • Regístrate Aquí
  • Deja tu comentario agradeciendo el aporte.

Descarga el código completo del Elemento Web y archivos necesarios (imágenes, librerias, plugins, frameword, etc)

Deja tu comentario