登录框效果是怎么实现的?

斧快不怕纽纹.
-民谚

效果可以参见下面的GIF示意:


我们可以借助CSS :placeholder-shown伪类,纯CSS,无任何JS,实现这样的占位符交互效果。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .input-fill-x {
            position: relative;

        }

        .input-label {
            position: absolute;
            left: 16px;
            top: 7px;
            pointer-events: none;
        }
        .input-control{
            padding: 0 10px;
            width: 200px;
            height:30px;
            font-size: 14px;
        }

        .input-fill:placeholder-shown::placeholder {
            color: transparent;
        }

        .input-fill:not(:placeholder-shown) ~ .input-label,
        .input-fill:focus ~ .input-label {
            color: #72a0ff;
            top: 14px;
            background: white;
            transform: scale(0.75) translate(0, -32px);
        }


        input:focus{
            outline:1px solid #98ccff;
            padding: 0 10px;
        }


    </style>
</head>
<body>
<h4>填充风格</h4>
<div class="input-fill-x">
    <input type="text" class="input-control input-fill" placeholder="邮箱">
    <label class="input-label">邮箱</label>
</div>

</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1 【教是最好的学】 在塔尖,第一种学习方式--"听讲",也就是老师在上面说,学生在下面听,这种我们最熟悉最常用的...
    巴中张公子阅读 1,252评论 0 0
  • 开场 今天我们的主角是伪类:placeholder-shown 效果 效果可以参见下面的GIF示意: 现在这种设计...
    grain先森阅读 2,705评论 0 87
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 16,554评论 4 61
  • 【1.5原文】. 子曰:“道千乘之国:敬事而信,节用而爱人,使民以时。” 【傅佩荣译文】 孔子说:“治理诸侯...
    jnvivian阅读 729评论 0 0
  • 今天是初伏的第一天,早上起来感觉有点闷。下午四五点钟开始下雨,看天气原本以为能下场大雨。结果却下了一点点,不仅...
    淡淡的优雅阅读 394评论 0 0

友情链接更多精彩内容