css 输入框动态特效

先上图

代码

<!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>

相关推荐

  1. Vue+ElementUI实现输入日期下拉动态展示

    2023-12-09 06:36:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-09 06:36:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-09 06:36:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-09 06:36:02       82 阅读
  4. Python语言-面向对象

    2023-12-09 06:36:02       91 阅读

热门阅读

  1. golang开发一个聊天系统例子

    2023-12-09 06:36:02       68 阅读
  2. HTML5 基础总结

    2023-12-09 06:36:02       68 阅读
  3. Qt OpenCV 学习(六):kmeans聚类算法实现背景替换

    2023-12-09 06:36:02       58 阅读
  4. 云计算ACP认证考试题库0-100

    2023-12-09 06:36:02       56 阅读
  5. ssh框架原理及流程

    2023-12-09 06:36:02       56 阅读
  6. G1 GC基本逻辑

    2023-12-09 06:36:02       44 阅读