To give a site an interesting and modern feel, the transition property can be used to expand the length of a search field when the user clicks into it.
Below is the search form we’ll apply our styles to. We have it inside a parent div
so that we can set the alignment of where the form will sit.
Add these styles to your style sheet.
.search_container {
text-align: left;
}
.my_search {
width: 160px;
box-sizing: border-box;
border: #bababa solid thin;
border-radius: 3px;
font-size: 16px;
padding: 12px 20px;
transition: width 0.4s ease-in-out;
}
.my_search:focus {
width: 100%;
}
.my_search:focus::placeholder {
color: white;
}
Examples
This example has the .search_container set to the left, and it will expand to the right.
.search_container {
text-align: left;
}
This example has the .search_container set to the right, and it will expand to the left.
.search_container {
text-align: right;
}
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.
Why 1SMARTchicken?
See More →
Thanks for your support!
CSS Books
All are affiliate links. Thank you for your support!
CSS NOTES:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
Feedback
If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.