【问题标题】:INPUT placeholder animation when typing输入时输入占位符动画
【发布时间】:2019-01-10 14:17:36
【问题描述】:

我一直在尝试找到一种方法来在用户开始输入时在占位符上模仿以下动画,就像在下面的 GIF 中一样:

Placeholder animation

我知道如何在用户专注于输入后立即为动画淡出设置动画,但我还没有找到任何关于如何在用户开始输入时执行此动画的信息

【问题讨论】:

标签: html css placeholder


【解决方案1】:

你好下面是你想要占位符动画的解决方案

input[type="text"] {
    font: 15px/24px "Lato", Arial, sans-serif;
    color: #333;
    width: 100%;
    box-sizing: border-box;
    letter-spacing: 1px;
}
.effect-16, .effect-17, .effect-18 {
    border: 0;
    padding: 4px 0;
    border-bottom: 1px solid #ccc;
    background-color: transparent;
}
.effect-16 ~ label {
    position: absolute;
    left: 0;
    width: 100%;
    top: 9px;
    color: #aaa;
    transition: 0.3s;
    z-index: -1;
    letter-spacing: 0.5px;
}
.effect-16 ~ .focus-border {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: #3399FF;
    transition: 0.4s;
}
.effect-16:focus ~ .focus-border, .has-content.effect-16 ~ .focus-border {
    width: 100%;
    transition: 0.4s;
}
.effect-16 ~ .focus-border {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background-color: #3399FF;
    transition: 0.4s;
    
}
input:focus {
  outline: 0;
}
.effect-16:focus ~ label, .has-content.effect-16 ~ label {
    top: -16px;
    font-size: 12px;
    color: #3399FF;
    transition: 0.3s;
}
.input-box {padding:50px 0px;}
.col-3 {
    float: left;
    width: 27.33%;
    margin: 40px 3%;
    position: relative;
}
<section class="input-box">
  <div class="container">
  
  
        <div class="row">
                    <div class="col-3 input-effect">
        	<input class="effect-16" type="text" placeholder="">
            <label>First Name</label>
            <span class="focus-border"></span>
        </div>
        <div class="col-3 input-effect">
        	<input class="effect-16" type="text" placeholder="">
            <label>Last Name</label>
            <span class="focus-border"></span>
        </div>
        <div class="col-3 input-effect">
        	<input class="effect-16" type="text" placeholder="">
            <label>Address</label>
            <span class="focus-border"></span>
        </div>
        <div class="col-3 input-effect">
        	<input class="effect-16" type="text" placeholder="">
            <label>Mobile</label>
            <span class="focus-border"></span>
        </div>
        </div>
</div>
        </section>

【讨论】:

    猜你喜欢
    • 2021-11-24
    • 2021-02-15
    • 2021-05-17
    • 1970-01-01
    • 2020-04-12
    • 2017-04-07
    • 1970-01-01
    • 2017-11-20
    • 2018-03-23
    相关资源
    最近更新 更多