HTML美观的搜索框怎么做?

2024-06-07 20:20

本文主要是介绍HTML美观的搜索框怎么做?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、“融情于景”1.0

<form action="" class="search-bar"><input type="search" name="search" pattern=".*\S.*" required><button class="search-btn" type="submit"><span>Search</span></button>
</form>
* {border: 0;box-sizing: border-box;margin: 0;padding: 0;
}
:root {font-size: calc(16px + (24 - 16)*(100vw - 320px)/(1920 - 320));
}
body, button, input {font: 1em Hind, sans-serif;line-height: 1.5em;
}
body, input {color: #171717;
}
body, .search-bar {display: flex;
}
body {background: #f1f1f1;height: 100vh;
}
.search-bar input,
.search-btn, 
.search-btn:before, 
.search-btn:after {transition: all 0.25s ease-out;
}
.search-bar input,
.search-btn {width: 3em;height: 3em;
}
.search-bar input:invalid:not(:focus),
.search-btn {cursor: pointer;
}
.search-bar,
.search-bar input:focus,
.search-bar input:valid  {width: 100%;
}
.search-bar input:focus,
.search-bar input:not(:focus) + .search-btn:focus {outline: transparent;
}
.search-bar {margin: auto;padding: 1.5em;justify-content: center;max-width: 30em;
}
.search-bar input {background: transparent;border-radius: 1.5em;box-shadow: 0 0 0 0.4em #171717 inset;padding: 0.75em;transform: translate(0.5em,0.5em) scale(0.5);transform-origin: 100% 0;-webkit-appearance: none;-moz-appearance: none;appearance: none;
}
.search-bar input::-webkit-search-decoration {-webkit-appearance: none;
}
.search-bar input:focus,
.search-bar input:valid {background: #fff;border-radius: 0.375em 0 0 0.375em;box-shadow: 0 0 0 0.1em #d9d9d9 inset;transform: scale(1);
}
.search-btn {background: #171717;border-radius: 0 0.75em 0.75em 0 / 0 1.5em 1.5em 0;padding: 0.75em;position: relative;transform: translate(0.25em,0.25em) rotate(45deg) scale(0.25,0.125);transform-origin: 0 50%;
}
.search-btn:before, 
.search-btn:after {content: "";display: block;opacity: 0;position: absolute;
}
.search-btn:before {border-radius: 50%;box-shadow: 0 0 0 0.2em #f1f1f1 inset;top: 0.75em;left: 0.75em;width: 1.2em;height: 1.2em;
}
.search-btn:after {background: #f1f1f1;border-radius: 0 0.25em 0.25em 0;top: 51%;left: 51%;width: 0.75em;height: 0.25em;transform: translate(0.2em,0) rotate(45deg);transform-origin: 0 50%;
}
.search-btn span {display: inline-block;overflow: hidden;width: 1px;height: 1px;
}/* Active state */
.search-bar input:focus + .search-btn,
.search-bar input:valid + .search-btn {background: #2762f3;border-radius: 0 0.375em 0.375em 0;transform: scale(1);
}
.search-bar input:focus + .search-btn:before, 
.search-bar input:focus + .search-btn:after,
.search-bar input:valid + .search-btn:before, 
.search-bar input:valid + .search-btn:after {opacity: 1;
}
.search-bar input:focus + .search-btn:hover,
.search-bar input:valid + .search-btn:hover,
.search-bar input:valid:not(:focus) + .search-btn:focus {background: #0c48db;
}
.search-bar input:focus + .search-btn:active,
.search-bar input:valid + .search-btn:active {transform: translateY(1px);
}@media screen and (prefers-color-scheme: dark) {body, input {color: #f1f1f1;}body {background: #171717;}.search-bar input {box-shadow: 0 0 0 0.4em #f1f1f1 inset;}.search-bar input:focus,.search-bar input:valid {background: #3d3d3d;box-shadow: 0 0 0 0.1em #3d3d3d inset;}.search-btn {background: #f1f1f1;}
}

二、“融情于景”2.0

<div class="container"><input type="text" placeholder="Search..."><div class="search"></div>
</div>
* {margin: 0;padding: 0;box-sizing: border-box;
}html, body {width: 100%;height: 100%;
}body {background: #252525;
}.container {position: absolute;margin: auto;top: 0;left: 0;right: 0;bottom: 0;width: 300px;height: 100px;
}
.container .search {position: absolute;margin: auto;top: 0;right: 0;bottom: 0;left: 0;width: 80px;height: 80px;background: crimson;border-radius: 50%;transition: all 1s;z-index: 4;box-shadow: 0 0 25px 0 rgba(0, 0, 0, 0.4);
}
.container .search:hover {cursor: pointer;
}
.container .search::before {content: "";position: absolute;margin: auto;top: 22px;right: 0;bottom: 0;left: 22px;width: 12px;height: 2px;background: white;transform: rotate(45deg);transition: all 0.5s;
}
.container .search::after {content: "";position: absolute;margin: auto;top: -5px;right: 0;bottom: 0;left: -5px;width: 25px;height: 25px;border-radius: 50%;border: 2px solid white;transition: all 0.5s;
}
.container input {font-family: "Inconsolata", monospace;position: absolute;margin: auto;top: 0;right: 0;bottom: 0;left: 0;width: 50px;height: 50px;outline: none;border: none;background: crimson;color: white;text-shadow: 0 0 10px crimson;padding: 0 80px 0 20px;border-radius: 30px;box-shadow: 0 0 25px 0 crimson, 0 20px 25px 0 rgba(0, 0, 0, 0.2);transition: all 1s;opacity: 0;z-index: 5;font-weight: bolder;letter-spacing: 0.1em;
}
.container input:hover {cursor: pointer;
}
.container input:focus {width: 300px;opacity: 1;cursor: text;
}
.container input:focus ~ .search {right: -250px;background: #151515;z-index: 6;
}
.container input:focus ~ .search::before {top: 0;left: 0;width: 25px;
}
.container input:focus ~ .search::after {top: 0;left: 0;width: 25px;height: 2px;border: none;background: white;border-radius: 0%;transform: rotate(-45deg);
}
.container input::placeholder {color: white;opacity: 0.5;font-weight: bolder;
}

这篇关于HTML美观的搜索框怎么做?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1040201

相关文章

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

怎么用idea创建一个SpringBoot项目

《怎么用idea创建一个SpringBoot项目》本文介绍了在IDEA中创建SpringBoot项目的步骤,包括环境准备(JDK1.8+、Maven3.2.5+)、使用SpringInitializr... 目录如何在idea中创建一个SpringBoot项目环境准备1.1打开IDEA,点击New新建一个项

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F