html, css make a search box with search icon (how to share)

Preface

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

Show results

Insert picture description here
Insert picture description here

The basic idea

1. The search image is placed above the search box with absolute positioning
2. The input box is set to indent the text, the size is the size of the search image plus the outer margins on the left and right sides of the image

ready

Just a search icon picture, similar to the picture below
Insert picture description here

Code

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>搜索框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="请输入搜索条件">
			<input type="submit" value="搜索">
		</form>	
	</div>
</body>
</html>

Recommended by other articles in this blog

It took two and a half days for the rookie back-end programmer to imitate and write the Ganji.com homepage, and come to watch!

CSS implements drop-down menu

A carousel diagram using only CSS? Come take a look!

Imitate a ball landing effect, and finally stop on the ground (simulation effect, CSS implementation)

If there is a screen of love, who would you give it to? (Simple implementation of native js and css to randomly generate 521 hearts)

Guess you like

Origin blog.csdn.net/L333333333/article/details/102326873