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>
相关推荐
nashane28 分钟前
HarmonyOS 6学习:Web组件同层渲染事件处理与智能长截图实现
前端·学习·harmonyos·harmonyos 5
大家的林语冰30 分钟前
Node 2026 发布,JS 三大新功能上线,最后一个奇偶版本
前端·javascript·node.js
nashane1 小时前
HarmonyOS 6学习:Web组件同层渲染触摸事件与长截图拼接实战
前端·学习·harmonyos·harmonyos 5
GISer_Jing2 小时前
浏览器 Agent 插件开发规格书 (SPEC)
前端·ai·前端框架·edge浏览器
别叫我->学废了->lol在线等2 小时前
评估总结模块(暂不做)
前端
清灵xmf2 小时前
CC Switch:解决 AI 编程工具配置
前端·人工智能·cc switch
IT_陈寒2 小时前
Redis缓存击穿把我坑惨了,原来这样解决才靠谱
前端·人工智能·后端
mfxcyh2 小时前
Vue3 右键菜单实现方案(基于 vue3-context-menu)
前端
treesforest2 小时前
从IP地址归属地查询到IP地理位置精准查询指南
服务器·前端·网络
LF男男2 小时前
WindmillBullect.cs
前端