The following code snippets show two examples of text input fields. When focusing, the bottom of the entrance increases in thickness and changes color.
The first example uses a combination of border-bottom and box-shadow to achieve the effect. In the second example, only the shadow is used. I think the effects should be the same. However, with a shadow shadow, only the example “jumps” when the transition is completed. What for? Is there any way to improve it?
The example is tested only on a stable version of Webkit.
input[type="text"] { border-top: none; border-left: none; border-right: none; padding: 0 0 8px 0; transition: box-shadow 0.3s, border 0.3s; will-change: box-shadow, border; outline: none; box-sizing: border-box; } #example1 { border-bottom-width: 1px; border-bottom-color: rgba(0, 0, 0, 0.26); } #example1:focus { border-bottom-color: #2196F3; box-shadow: inset 0 -1px 0 #2196F3; } #example2 { border-bottom: none; padding-bottom: 9px; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .26); } #example2:focus { box-shadow: inset 0 -2px 0 #2196F3; }
<input type="text" id="example1" placeholder="I'm a good example"> <input type="text" id="example2" placeholder="I'm a bad example">
source share