Project Introduction: In this project, we are going to implement a car running on a track using HTML and CSS with sound effects
File structure:
- . index.html
- . style.css
- .css/all.css
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="css/all.css">
<title>search box </title>
</head>
<body>
<div class="searchBox">
<div class="icon"><i class="fas fa-search"></i></div>
<div class="input">
<input type="text" placeholder="Search" id="mysearch">
</div>
<span class="clear" onclick="document.getElementById('mysearch').value='' "><i class="fas fa-times"></i></span>
</div>
<script>
const icon = document.querySelector('.icon');
const searchBox = document.querySelector('.searchBox');
icon.onclick = function() {
searchBox.classList.toggle('active')
}
</script>
</body>
style.css: The following is the code for file “style.css” which is used in the above HTML code.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: crimson;
}
.searchBox {
position: relative;
width: 60px;
height: 60px;
background: #fff;
border-radius: 60px;
transition: 0.5s;
box-shadow: 0 0 0 5px #2573ef;
overflow: hidden;
}
.searchBox .icon {
position: absolute;
top: 0;
left: 0;
width: 60px;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
font-size: 25px;
color: #2573ef;
z-index: 1;
background: #fff;
}
.searchBox .input {
position: relative;
width: 300px;
height: 60px;
left: 60px;
display: flex;
justify-content: center;
align-items: center;
}
.searchBox .input input {
position: absolute;
top: 0;
width: 100%;
height: 100%;
border: none;
outline: none;
padding: 10px 0;
font-size: 18px;
}
.clear {
position: absolute;
top: 50%;
height: 15px;
width: 15px;
right: 15px;
display: flex;
justify-content: center;
align-items: center;
transform: translateY(-50%);
cursor: pointer;
color: #999;
font-size: 18px;
}
.searchBox.active {
width: 360px;
}
0 Comments