本文通过实例代码给大家分享8款纯CSS3实现的搜索框功能,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友参考下吧
效果图:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>8款纯CSS3搜索框</title> <link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> <link rel="stylesheet" href="style.css"> <style> * { box-sizing: border-box; } body { margin: 0; padding: 0; background: #494A5F; font-weight: 500; font-family: "Microsoft YaHei","宋体","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif, FreeSans, Arimo; } #container { width: 500px; height: 820px; margin: 0 auto; } p.search {padding: 30px 0;} form { position: relative; width: 300px; margin: 0 auto; } input, button { border: none; outline: none; } input { width: 100%; height: 42px; padding-left: 13px; padding-right:46px; } button { height: 42px; width: 42px; cursor: pointer; position: absolute; } /*搜索框1*/ .bar1 {background: #A3D0C3;} .bar1 input { border: 2px solid #7BA7AB; border-radius: 5px; background: #F9F0DA; color: #9E9C9C; } .bar1 button { top: 0; right: 0; background: #7BA7AB; border-radius: 0 5px 5px 0; } .bar1 button:before { content: "\f002"; font-family: FontAwesome; font-size: 16px; color: #F9F0DA; } /*搜索框2*/ .bar2 {background: #DABB52;} .bar2 input, .bar2 button { border-radius: 3px; } .bar2 input { background: #F9F0DA; } .bar2 button { height: 26px; width: 26px; top: 8px; right: 8px; background: #F15B42; } .bar2 button:before { content: "\f105"; font-family: FontAwesome; color: #F9F0DA; font-size: 20px; font-weight: bold; } /*搜索框3*/ .bar3 {background: #F9F0DA;} .bar3 form {background: #A3D0C3;} .bar3 input, .bar3 button { background: transparent; } .bar3 button { top: 0; right: 0; } .bar3 button:before { content: "\f002"; font-family: FontAwesome; font-size: 16px; color: #F9F0DA; } /*搜索框4*/ .bar4 {background: #F15B42;} .bar4 form { background: #F9F0DA; border-bottom: 2px solid #BE290E; } .bar4 input, .bar4 button { background: transparent; } .bar4 button { top: 0; right: 0; } .bar4 button:before { content: "\f178"; font-family: FontAwesome; font-size: 20px; color: #be290e; } /*搜索框5*/ .bar5 {background: #683B4D;} .bar5 input, .bar5 button { background: transparent; } .bar5 input { border: 2px solid #F9F0DA; } .bar5 button { top: 0; right: 0; } .bar5 button:before { content: "\f002"; font-family: FontAwesome; font-size: 16px; color: #F9F0DA; } .bar5 input:focus { border-color: #311c24 } /*搜索框6*/ .bar6 {background: #F9F0DA;} .bar6 input { border: 2px solid #c5464a; border-radius: 5px; background: transparent; top: 0; right: 0; } .bar6 button { background: #c5464a; border-radius: 0 5px 5px 0; width: 60px; top: 0; right: 0; } .bar6 button:before { content: "搜索"; font-size: 13px; color: #F9F0DA; } /*搜索框7*/ .bar7 {background: #7BA7AB;} .bar7 form { height: 42px; } .bar7 input { width: 250px; border-radius: 42px; border: 2px solid #324B4E; background: #F9F0DA; transition: .3s linear; float: right; } .bar7 input:focus { width: 300px; } .bar7 button { background: none; top: -2px; right: 0; } .bar7 button:before{ content: "\f002"; font-family: FontAwesome; color: #324b4e; } /*搜索框8*/ .bar8 {background: #B46381;} .bar8 form { height: 42px; } .bar8 input { width: 0; padding: 0 42px 0 15px; border-bottom: 2px solid transparent; background: transparent; transition: .3s linear; position: absolute; top: 0; right: 0; z-index: 2; } .bar8 input:focus { width: 300px; z-index: 1; border-bottom: 2px solid #F9F0DA; } .bar8 button { background: #683B4D; top: 0; right: 0; } .bar8 button:before { content: "\f002"; font-family: FontAwesome; font-size: 16px; color: #F9F0DA; } </style> </head> <body> <p id="container"> <p class="search bar1"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar2"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar3"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar4"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar5"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar6"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar7"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> <p class="search bar8"> <form> <input type="text" placeholder="请输入您要搜索的内容..."> <button type="submit"></button> </form> </p> </p> </body> </html>
以上是纯CSS3实现搜索框功能实例展示的详细内容。更多信息请关注PHP中文网其他相关文章!

具有CSS的自定义光标很棒,但是我们可以将JavaScript提升到一个新的水平。使用JavaScript,我们可以在光标状态之间过渡,将动态文本放置在光标中,应用复杂的动画并应用过滤器。

互动CSS动画和元素相互启动的元素在2025年似乎更合理。虽然不需要在CSS中实施乒乓球,但CSS的灵活性和力量的增加,可以怀疑Lee&Aver Lee&Aver Lee有一天将是一场

有关利用CSS背景滤波器属性来样式用户界面的提示和技巧。您将学习如何在多个元素之间进行背景过滤器,并将它们与其他CSS图形效果集成在一起以创建精心设计的设计。

好吧,事实证明,SVG的内置动画功能从未按计划进行弃用。当然,CSS和JavaScript具有承载负载的能力,但是很高兴知道Smil并没有像以前那样死在水中

是的,让#039;跳上文字包装:Safari Technology Preview In Pretty Landing!但是请注意,它与在铬浏览器中的工作方式不同。

此CSS-tricks更新了,重点介绍了年鉴,最近的播客出现,新的CSS计数器指南以及增加了几位新作者,这些新作者贡献了有价值的内容。

在大多数情况下,人们展示了@Apply的@Apply功能,其中包括Tailwind的单个property实用程序之一(会改变单个CSS声明)。当以这种方式展示时,@Apply听起来似乎很有希望。如此明显


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)