css 输入框动态特效

先上图

代码

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>css 输入框动效</title>
    <style>
        .inputBox {
            position: relative;
            width: 250px;
        }

        .inputBox input {
            width: 100%;
            padding: 10px;
            border: 1px solid #cccccc;
            border-radius: 5px;
            font-size: 1em;
            outline: none;
        }

        .inputBox span {
            position: absolute;
            left: 0;
            top: 0;
            padding: 10px;
            font-size: 1em;
            pointer-events: none;
            color: #cccccc;
        }

        .inputBox input:valid ~ span,
        .inputBox input:focus ~ span {
            color: orangered;
            transform: translateX(10px) translateY(-7px);
            font-size: 0.65em;
            padding: 0 10px;
            background: #ffffff;
        }
    </style>
</head>
<body>
<div class="inputBox">
    <input type="text" required/>
    <span>用户名</span>
</div>
</body>
</html>
相关推荐
泯泷15 分钟前
手搓JSVM第 9 篇:闭包:函数如何记住外部变量
前端·javascript·前端框架
晴天1632 分钟前
前端 SSR、BFF 原理介绍
前端·javascript·网络·html
全栈技术负责人1 小时前
AI 效能工具建设:Agent 可观测性技能技术方案与实践
前端·ai·ai编程
梦想平凡1 小时前
百游棋牌源代码开发搭建教程(一):全端工程结构、开发环境配置与首次启动验证
前端·javascript·源代码管理
妙码生花2 小时前
两个月 59 篇 AI 开发日志 + Golang 商业级实战项目收工后,得来的 AI 使用心法-上
前端·后端·gin
vx-Biye_Design2 小时前
springboot中国传统节日宣传平台49078-计算机课程设计、毕业设计
java·前端·vue.js·spring boot·后端·课程设计·idea
妙码生花2 小时前
两个月 59 篇 AI 开发日志 + Golang 商业级实战项目收工后,得来的 AI 使用心法-下
前端·后端·go
计算机魔术师3 小时前
Beren Millidge、John Schulman、Charlie O'Neill 对谈递归自我改进离我们还有多远
前端
MetaLite3 小时前
Java 时间处理的两个坑:单位误判,半秒算成一秒
java·开发语言·前端
hiahiahia1233 小时前
SSE 到底是什么?
前端·人工智能