Project 4 - Responsive Hidden Search Widget

About:
    In this Blog, We will be designing Responsive Hidden Search Widget. I am implementing this using simple Html, CSS and JavaScript , we are not using any frameworks.

This is simple search button which is responsive and having hidden search widget.

You can find the source code for this below and I have attached the video of the output for reference.

index.html - 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />
    <link rel="stylesheet" href="style.css" />
    <title>Responsive Hidden Search Widget</title>
  </head>
  <body>
    <div class="search">
      <input type="text" class="input" placeholder="Search...">
      <button class="btn">
        <i class="fas fa-search"></i>
      </button>
    </div>
    <script src="script.js"></script>
  </body>
</html>

style.css -

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

* {
  box-sizingborder-box;
}

body {
  background-image: linear-gradient(90deg#4f8cc5#4f8cc5);
  font-family'Roboto'sans-serif;
  displayflex;
  align-itemscenter;
  justify-contentcenter;
  height100vh;
  overflowhidden;
  margin0;
}

.search {
  positionrelative;
  height50px;
}

.search .input {
  background-color#fff;
  border0;
  font-size18px;
  padding15px;
  height50px;
  width50px;
  transition: width 0.3s ease;
}

.btn {
  background-color#fff;
  border0;
  cursorpointer;
  font-size24px;
  positionabsolute;
  top0;
  left0;
  height50px;
  width50px;
  transition: transform 0.3s ease;
}

.btn:focus,
.input:focus {
  outlinenone;
}

.search.active .input {
  width200px;
}

.search.active .btn {
  transform: translateX(198px);
}

script.js -

const search = document.querySelector('.search')
const btn = document.querySelector('.btn')
const input = document.querySelector('.input')

btn.addEventListener('click', () => {
    search.classList.toggle('active')
    input.focus()
})

OUTPUT:-
    
    


Comments

Popular posts from this blog

Project 3 - Customized Rotating Navigation

Project 2 - Progress Steps

Project 5 - Customized Scroll Animation