HTML Academy
Text input field, step 3
Smooth transitions29/29
Back to the list of tasks
  • 1. The transition-duration property
  • 2. Transition duration, step 2
  • 3. The transition-property: which properties can be changed smoothly?
  • 4. The transition-delay property
  • 5. The “form” of the transition, transition-timing-function
  • 6. transition-timing-function, step 2
  • 7. transition-timing-function, step 3
  • 8. transition-timing-function, step 4
  • 9. Paper buttons, step 1
  • 10. Paper buttons, step 2
  • 11. Paper buttons, step 3
  • 12. Checkboxes, step 1
  • 13. Checkboxes, step 2
  • 14. Checkboxes, step 3
  • 15. Radio buttons, step 1
  • 16. Radio buttons, step 2
  • 17. Radio buttons, step 3
  • 18. Toggle switches, step 1
  • 19. Toggle switches, step 2
  • 20. Toggle switches, step 3
  • 21. Toggle switches, step 4
  • 22. The transformer icon, step 1
  • 23. The transformer icon, step 2
  • 24. The transformer icon, step 3
  • 25. The transformer icon, step 4
  • 26. Text input field, step 1
  • 27. Text input field, step 2
  • 28. Text input field, step 3
  • 29. Text input field, step 4
List of tasks
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Text input field, step 4

We still need to liven up the decorative selection effect.

In the initial state, there is no selection, so the first thing we need to do is change its width to zero. In order to allow the decorative selection effect to appear when the input field receives the focus, use the CSS rule with these selectors:

input:focus ~ .label-box::before,
input:valid ~ .label-box::after {
  ...
}

And in this rule, set the desired width of the border parts.

In order to allow the selection to appear and disappear smoothly, we need to set a smooth transition for both of its parts in this rule:

.label-box::before,
.label-box::after {
  ...
}

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Text input field, step 4</title> <meta charset="utf-8"> <link rel="stylesheet" href="material.css"> <link rel="stylesheet" href="style.css"> </head> <body class="purple-theme"> <section class="card"> <h1 class="question"><span>What was the very first web browser was called?</span></h1> <form class="answers" action="https://echo.htmlacademy.ru/courses" method="post"> <button class="fab" type="submit">&#58882;</button> <div> <input type="text" required> <div class="label-box"> <label>Word in English</label> </div> </div> </form> </section> </body> </html>
CSS
.label-box { position: relative; width: 270px; } .label-box::before, .label-box::after { position: absolute; bottom: 1px; width: 50%; height: 2px; background-color: #757575; content: ""; } .label-box::before { left: 50%; } .label-box::after { right: 50%; } input:focus ~ .label-box::before, input:focus ~ .label-box::after { } input { box-sizing: border-box; padding: 5px; width: 270px; border: none; border-bottom: 1px solid #757575; font-size: 18px; } label { position: absolute; top: -36px; color: #757575; font-size: 18px; transition: 0.2s ease all; pointer-events: none; } input:focus ~ .label-box label, input:valid ~ .label-box label { font-size: 14px; transform: translateY(-20px); }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. Change the width of the pseudo-elements .label-box::before, .label-box::after to 0,
    2. and when the input field is switched to a focused state, assign a width of 50% to the pseudo-elements.
    3. Finally, assign a smooth transition for the width property of the .label-box::before, .label-box::after pseudo-elements that is 0.2s in duration.

    Click inside and outside of the input field in order to test the result.

    1. Select the correct answer to the quiz question, and press the round button to check your answer.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.