你如何进行占位符和标签转换? [英] How do you make Placeholder and Label Transitions?

查看:27
本文介绍了你如何进行占位符和标签转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am looking to find an example of how to make a label / placeholder transition move up and out of placeholder position into a label position and vice versa..

Example: https://www.xero.com/us/signup/

解决方案

I found a good Codepen showing an example of how to do it in CSS.

HTML:

<div class="row">
    <input id="name" type="text" name="name">
    <label for="name">Full Name</label>
</div>

CSS:

.row {
  position: relative;
  margin-top: 35px;
}

input {
    display: block;
    padding: 8px 12px;
    width: 100%;
    max-width: 300px;
    border-radius: 5px;
    border: 0;
}

label {
    position: absolute;
    font-weight: 600;
    color: #777777;
    top: 50%;
    left: 12px;
    transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    -webkit-transform: translateY(-50%);
    cursor: text;
    user-select: none;
    transition: 0.15s ease-in-out;
}

input[data-empty="false"] + label,
input:valid + label,
input:focus + label {
    top: -10px;
    left: 0px;
    font-size: 10px;
    color: #ffffff;
}

Example: https://codepen.io/sivan/pen/alKwf

这篇关于你如何进行占位符和标签转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆