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

相关文章

Vue和React受控组件的区别小结

《Vue和React受控组件的区别小结》本文主要介绍了Vue和React受控组件的区别小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录背景React 的实现vue3 的实现写法一:直接修改事件参数写法二:通过ref引用 DOMVu

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

Vue3绑定props默认值问题

《Vue3绑定props默认值问题》使用Vue3的defineProps配合TypeScript的interface定义props类型,并通过withDefaults设置默认值,使组件能安全访问传入的... 目录前言步骤步骤1:使用 defineProps 定义 Props步骤2:设置默认值总结前言使用T

基于Python Playwright进行前端性能测试的脚本实现

《基于PythonPlaywright进行前端性能测试的脚本实现》在当今Web应用开发中,性能优化是提升用户体验的关键因素之一,本文将介绍如何使用Playwright构建一个自动化性能测试工具,希望... 目录引言工具概述整体架构核心实现解析1. 浏览器初始化2. 性能数据收集3. 资源分析4. 关键性能指

从入门到精通详解LangChain加载HTML内容的全攻略

《从入门到精通详解LangChain加载HTML内容的全攻略》这篇文章主要为大家详细介绍了如何用LangChain优雅地处理HTML内容,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录引言:当大语言模型遇见html一、HTML加载器为什么需要专门的HTML加载器核心加载器对比表二

前端如何通过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电子邮件输入编程框