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>
相关推荐
miss10 分钟前
JavaScript 异步循环完全指南:从踩坑到最佳实践
前端
家里有蜘蛛10 分钟前
从 Webpack 迁移到 Rspack 后,循环依赖为什么炸了?一个 const vs var 引发的血案
前端
山_雨11 分钟前
前端重连机制
前端
Cache技术分享16 分钟前
355. Java IO API -去除路径中的冗余信息
前端·后端
牛马11126 分钟前
Flutter CustomPaint
开发语言·前端·javascript
炽烈小老头37 分钟前
函数式编程范式(三)
前端·typescript
ruoyusixian1 小时前
chrome二维码识别查插件
前端·chrome
fengfuyao9851 小时前
一个改进的MATLAB CVA(Change Vector Analysis)变化检测程序
前端·算法·matlab
yuhaiqiang2 小时前
为什么这道初中数学题击溃了所有 AI
前端·后端·面试
djk88882 小时前
支持手机屏幕的layui后台html模板
前端·html·layui