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

Example analysis of the use of GROUP_CONCAT in MySQL

This article uses an example to describe how to u...

Docker uses the Prune command to clean up the none image

Table of contents The creation and confusion of n...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...

CSS warped shadow implementation code

This article introduces the implementation code o...

Summary of Vue component basics

Component Basics 1 Component Reuse Components are...

Key features of InnoDB - insert cache, write twice, adaptive hash index details

The key features of the InnoDB storage engine inc...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

A brief discussion on two methods to solve space-evenly compatibility issues

Since its launch in 2009, flex has been supported...

How to use skeleton screen in vue project

Nowadays, application development is basically se...

Docker installs redis 5.0.7 and mounts external configuration and data issues

Redis is an open source NoSQL database written in...

Use pure CSS to disable the a tag in HTML without JavaScript

In fact, this problem has already popped up when I...