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>
相关推荐
ayqy贾杰15 小时前
我同事,40了,他vibe coding了个App
前端·ios·客户端
暗冰ཏོ15 小时前
《2026 Vue2 + Vue3 完整学习指南:基础语法、路由缓存、登录拦截、项目实战与面试题》
前端·vue.js·vue·vue3·vue2
蜡台15 小时前
VUE 侧边按钮组,可自定义位置
前端·javascript·css
AI科技星16 小时前
维度原本——基于超复数谱系的全域维度统一理论
c语言·前端·javascript·网络·electron
kyriewen16 小时前
14MB VS 15KB:前React核心成员用AI写了个排版库,让Safari快了一千倍
前端·javascript·react.js
幸运小圣16 小时前
动态表格在 Vue 3 中的实现指南【前端】
前端·javascript·vue.js
SwJieJie16 小时前
Day 3|表格表单分页范式与 vue-request 最佳实践:从配置驱动到业务落地
前端·javascript·vue.js
ZengLiangYi16 小时前
任务队列设计:p-queue 限速 + 重试策略
前端·javascript·后端
sugar__salt16 小时前
从零吃透 ES6 核心:变量声明、作用域、变量提升与坑点
前端·javascript·ecmascript·es6
罗超驿16 小时前
1.HTML基础入门:标签、属性与路径详解(VSCode开发环境)
前端·vscode·html