Douglas Gaskell
Douglas Gaskell

Reputation: 10030

Border-like transition causes content to shift

Title pretty much sums it up, here is a demonstration and the CSS thus far.

.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

https://jsfiddle.net/a554h0oo/

What I am trying to achieve:

enter image description here

This is what I get:

enter image description here

Upvotes: 3

Views: 264

Answers (2)

F. Kim
F. Kim

Reputation: 53

try this code.

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

Upvotes: 0

vals
vals

Reputation: 64164

When you set border : transparent, you are reseting the border width to 1 in the top .

Set border-color instead

.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);
}
<div class="edit input">
    <input type="text">
    <span class="bar"></span>
</div>

<br>
<br> stuff
<br> other stuff

Upvotes: 3

Related Questions