CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress
CSS Snippets

Code Snippet

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.

				
					<div class="search_container">
    <form>
      <input type="text" class="my_search" name="search" placeholder="Search site...">
    </form>
</div>
				
			

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.

CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

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.