HTML如何在网页中加一个搜索框,基于html css实现带搜索图标的搜索框功能

前言

给大家分享一下前端用处很多的带小图标的搜索框的制作方法。

效果展示

def651aed683c8ec2d34f298bc5d50e5.png

65c3f3230bae83b1663677a43519cb46.png

基本思路

1、搜索图像用绝对定位放到搜索框的上方

2、input框设置文本缩进,大小为搜索图像大小加上图像左右两边的外边距

准备

只需一个搜索图标图片,类似于下图

0920d3f9b07189d1284dd0bd67304177.png

代码

搜索框demo

*{

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;

}

总结

以上所述是小编给大家介绍的基于html css实现带搜索图标的搜索框功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

  • 5
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Django 实现网页搜索功能,可以采用以下步骤: 1. 安装搜索引擎库 Django 可以使用多种搜索引擎库,如 Elasticsearch、Solr、Whoosh 等。选择一个适合自己的搜索引擎库,安装对应的 Python 库即可。 2. 定义搜索模型 在 Django ,我们可以使用模型定义搜索模型,也可以使用无模型的搜索。如果使用模型定义搜索模型,则需要在模型定义搜索字段,例如: ```python from django.db import models class Book(models.Model): title = models.CharField(max_length=100) author = models.CharField(max_length=50) content = models.TextField() ``` 3. 定义搜索视图 定义搜索视图时,需要获取用户输入的搜索关键字,并使用搜索引擎库进行搜索。例如,使用 Whoosh 库进行搜索: ```python from django.shortcuts import render from whoosh.index import create_in, open_dir from whoosh.fields import * from whoosh.qparser import QueryParser from .models import Book def search(request): q = request.GET.get('q', '') index_dir = 'path/to/index/dir' ix = open_dir(index_dir) parser = QueryParser("content", schema=ix.schema) q = parser.parse(q) with ix.searcher() as searcher: results = searcher.search(q) books = [] for r in results: book = Book.objects.get(id=r['id']) books.append(book) return render(request, 'search.html', {'books': books}) ``` 4. 定义搜索模板 最后,定义搜索结果模板,将搜索结果展示给用户即可。 以上是 Django 实现网页搜索功能的基本步骤,具体实现方式还需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值