边境式过渡导致内容发生变化

时间:2016-09-30 07:50:21

标签: html css css3 css-transitions

标题几乎总结了一下,这是一个演示和CSS到目前为止。



.edit.input {
    display: inline-block;
}

.edit.input input {
    border: none;
    border-bottom: 1px solid #D4D4D5;
}

.edit.input input:focus {
    outline: none;
    border: transparent;
}

.bar {
    display: block;
}

.bar:after {
    content: '';
    display: block;
    transform: scaleX(0);
    bottom: -2px;
    height: 2px;
    background: #48afb9;
    transition: 300ms ease all;
}

.edit.input input:focus ~ .bar:after {
    transform: scaleX(1);
}

<div class="edit input">
    <input type="text">
    <span class="bar"></span>
</div>

<br>
<br> stuff
<br> other stuff
&#13;
&#13;
&#13;

https://jsfiddle.net/a554h0oo/

我想要实现的目标:

enter image description here

这就是我得到的:

enter image description here

2 个答案:

答案 0 :(得分:1)

当你设置border:transparent时,你正在将边框宽度重置为顶部的。

设置border-color

&#13;
&#13;
.edit.input {
    display: inline-block;
}

.edit.input input {
    border: none;
    border-bottom: 1px solid #D4D4D5;
}

.edit.input input:focus {
  outline: none;
    border-color: transparent; /* changed */
}

.bar {
    display: block;
}

.bar:after {
    content: '';
    display: block;
    transform: scaleX(0);
    bottom: -2px;
    height: 2px;
    background: #48afb9;
    transition: 300ms ease all;
}

.edit.input input:focus ~ .bar:after {
    transform: scaleX(1);
}
&#13;
<div class="edit input">
    <input type="text">
    <span class="bar"></span>
</div>

<br>
<br> stuff
<br> other stuff
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这段代码。

<style type="text/css">
    .edit.input {
        display: inline-block;
    }

    .edit.input input {
        border: none;
        border-bottom: 1px solid #F312FE;
    }

    .edit.input input:focus { /* virtual selecter */
        outline: none;
        border-color:transparent;
    }

    .bar:after {  /* virtual selecter */
        content: '';
        display: block;
        transform: scaleX(0); /* width * 0 */
        bottom: -2px;
        height: 2px;
        background: #48afb9;
        transition: 300ms ease all;
    }

    .edit.input input:focus ~ .bar:after {
        transform: scaleX(1); /* animation speed : 1 */
    }
}
</style>
<div class="edit input">
<input type="text">
    <div class="bar">
    </div>
</div>