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>
相关推荐
爱健身的小刘同学26 分钟前
Vue 3 + Leaflet 地图可视化
前端·javascript·vue.js
神秘的猪头39 分钟前
Ajax 数据请求:从零开始掌握异步通信
前端·javascript
稀饭521 小时前
用changeset来管理你的npm包版本
前端·npm
TeamDev1 小时前
基于 Angular UI 的 C# 桌面应用
前端·后端·angular.js
卡尔特斯1 小时前
CSS 特殊符号 / 英文导致换行问题速查表
css
Komorebi゛1 小时前
【CSS】斜角流光样式
前端·css
Irene19911 小时前
CSS 废弃属性分类总结
前端·css
青莲8431 小时前
Android 事件分发机制 - 事件流向详解
android·前端·面试
musashi1 小时前
用 Electron 写了一个 macOS 版本的 wallpaper(附源码、下载地址)
前端·vue.js·electron
满天星辰2 小时前
Typescript之类型总结大全
前端·typescript