Implementing search box function with search icon based on html css

Implementing search box function with search icon based on html css

Preface

Let me share with you how to make a search box with small icons which is very useful in the front end.

Effect display

insert image description here
insert image description here

Basic idea

1. Use absolute positioning to place the search image above the search box

2. Set the text indentation of the input box to the size of the search image plus the margins on the left and right sides of the image

Prepare

Just a search icon image, similar to the one below

insert image description here

Code

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Search box demo</title>
 <style type="text/css">
  *{
   margin: 0;
   padding: 0;
  }
  body{
   width: 100vw;
   height: 100vh;
   background: radial-gradient(at center,
    #3498db,#2980b9);
   display: flex;
   justify-content: center;
   align-items: center;
  }
  div.search{
   height: 40px;
   width: 500px;  
  }
  div.search form{
   width: 100%;
   height: 100%;
  }
  div.search form input:nth-child(2){
   width: 400px;
   height: 100%;
   font-size: 16px;
   text-indent: 40px;
   border: none;
   float: left;
  }
  div.search form input:nth-child(3){
   width: 100px;
   height: 100%;
   font-size: 16px;
   letter-spacing: 5px;
   border: none;
  }
  div.search form img{
   position: absolute;
   left: 50vw;
   transform: translateX(-250px);
   margin-top: 10px;
   margin-left: 10px;
   height: 20px;
  }
 </style>
</head>
<body>
 <div class="search">
  <form action="#" method="post">
   <img src="./search_ico.png" alt="">
   <input type="text" name="condition" placeholder="Please enter the search condition">
   <input type="submit" value="Search">
  </form> 
 </div>
</body>
</html>

Summarize

The above is the search box function with search icon based on HTML CSS introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Several navigation directions that will be popular in the future

>>:  MySQL group query optimization method

Recommend

Completely uninstall MySQL database in Windows system to reinstall MySQL

1. In the control panel, uninstall all components...

5 ways to quickly remove the blank space of Inline-Block in HTML

The inline-block property value becomes very usef...

How to force vertical screen on mobile pages

I recently wrote a mobile page at work, which was...

Nginx content cache and common parameter configuration details

Use scenarios: The project's pages need to lo...

MySQL binlog opening steps

Binlog is a binary log file that is used to recor...

Example of converting timestamp to Date in MySQL

Preface I encountered a situation at work: In the...

W3C Tutorial (1): Understanding W3C

W3C, an organization founded in 1994, aims to unl...

How to implement the jQuery carousel function

This article shares the implementation code of jQ...

Negative distance (empathy) - iterative process of mutual influence

Negative distance refers to empathy. Preface (rai...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...

Comparative Analysis of UI Applications of Image Social Networking Sites (Figure)

In our life, work and study, social networks have ...

Example code for converting html table data to Json format

The javascript function for converting <table&g...