Skip to content

Commit b8d5ee9

Browse files
committed
hidden search widget using html css js
1 parent f9adbab commit b8d5ee9

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

hidden search widget/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
8+
<link rel="stylesheet" href="style.css">
9+
<title>My Project</title>
10+
</head>
11+
<body>
12+
<div class="search">
13+
<input type="text" placeholder="Search..." class="input">
14+
<button class="btn">
15+
<i class="fas fa-search"></i>
16+
</button>
17+
</div>
18+
<script src="script.js"></script>
19+
</body>
20+
</html>

hidden search widget/script.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const search = document.querySelector('.search')
2+
const btn = document.querySelector('.btn')
3+
const input = document.querySelector('.input')
4+
5+
btn.addEventListener('click', () => {
6+
search.classList.toggle('active')
7+
input.focus()
8+
})

hidden search widget/style.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
2+
3+
*{
4+
box-sizing: border-box;
5+
}
6+
7+
body{
8+
background-image: linear-gradient(90deg, #7d5fff, #7158e2);
9+
font-family: 'Roboto', sans-serif;
10+
margin: 0;
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
height: 100vh;
15+
overflow: hidden;
16+
}
17+
18+
19+
.search {
20+
position: relative;
21+
height: 50px;
22+
}
23+
24+
.search .input{
25+
background-color: #fff;
26+
border: 0;
27+
font-size: 18px;
28+
padding: 15px;
29+
height: 50px;
30+
width: 50px;
31+
transition: width 0.3s ease;
32+
}
33+
34+
.btn{
35+
background-color: #fff;
36+
border: 0;
37+
cursor: pointer;
38+
font-size: 24px;
39+
position: absolute;
40+
top: 0;
41+
left: 0;
42+
height: 50px;
43+
width: 50px;
44+
transition: transform 0.3s ease;
45+
46+
}
47+
48+
.btn:focus, .input:focus{
49+
outline: none;
50+
51+
}
52+
53+
.search.active .input{
54+
width: 200px;
55+
}
56+
57+
.search.search.active .btn {
58+
transform: translateX(198px);
59+
}

0 commit comments

Comments
 (0)