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>
相关推荐
共享家952722 分钟前
基于 Coze 工作流搭建历史主题图片生成器
前端·人工智能·js
zhaoyin199424 分钟前
fiddler抓包工具使用
前端·测试工具·fiddler
Doris89342 分钟前
【 Vue】 Vue3全面讲解文档
前端·javascript·vue.js
Hexene...1 小时前
【前端Vue】如何快速直观地查看引入的前端依赖?名称版本、仓库地址、开源协议、作者、依赖介绍、关系树...(Node Modules Inspector)
前端·javascript·vue.js
fanruitian1 小时前
div水平垂直居中
前端·javascript·html
旭久1 小时前
react+antd实现一个支持多种类型及可新增编辑搜索的下拉框
前端·javascript·react.js
aesthetician1 小时前
Spotify 网页版前端技术全面解析
前端
咩图1 小时前
Sketchup软件二次开发+Ruby+VisualStudioCode
java·前端·ruby
陈振wx:zchen20081 小时前
CSS2-3
css·css3·css2
Можно1 小时前
从零开始:Vue 框架安装全指南
前端·javascript·vue.js