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>
相关推荐
HashTang2 分钟前
【AI 编程实战】第 3 篇:后端小白也能写 API:AI 带我 1 小时搭完 Next.js 服务
前端·后端·ai编程
三年三月4 分钟前
React 中 CSS Modules 详解
前端·css
粉末的沉淀14 分钟前
tauri:关闭窗口后最小化到托盘
前端·javascript·vue.js
赵庆明老师22 分钟前
NET 使用SmtpClient 发送邮件
java·服务器·前端
绝世唐门三哥35 分钟前
使用Intersection Observer js实现超出视口固定底部按钮
开发语言·前端·javascript
鲸落落丶1 小时前
Vue Router路由
前端·javascript·vue.js
阿呜的边城1 小时前
终于还是吃上了react-i18next的细糠
前端·前端框架
米方1 小时前
ElementPlus 穿梭框支持批量穿梭
前端·javascript·vue.js
InkHeart1 小时前
uni-app开发路上的坑
前端·vue.js
用户4099322502121 小时前
Vue3中v-bind:class与v-bind:style如何实现条件样式、组件样式合并与深层响应式管理?
前端·ai编程·trae