Build a Responsive Search Bar in 30 Minutes | HTML & CSS

Share

Summary

This tutorial guides you through building a responsive search bar using HTML and CSS. Learn about structuring HTML for a search bar, incorporating Font Awesome icons, utilizing Flexbox for layout and responsiveness, and styling various elements including input fields, shadows, and placeholders. The video emphasizes best practices for a production-ready search bar.

Highlights

Layout with Flexbox
00:08:50

To arrange the icons and input field horizontally and responsively, Flexbox is introduced. A wrapper div with the class 'input-wrapper' is created around all elements. Applying 'display: flex' to this wrapper aligns its children horizontally. 'align-items: center' is used to vertically center the items.

Introduction to Building a Search Bar
00:00:00

The video introduces building and styling a search bar using HTML and CSS, focusing on input styling, search bars, and working with icons. The development environment used is Codepen.io for its rapid updating capabilities.

Deconstructing the Search Bar Structure
00:01:02

The search bar is broken down into four main components: an outer container, a magnifying glass icon, the text input field, and an 'x' icon. The instructor emphasizes building these individual elements first before styling.

Creating the Input Field and Basic Styling
00:02:23

An HTML 'input' tag with 'type="text"' and a 'placeholder' of 'Search' is created. Initial CSS styling is applied to increase the font size to 1.5 rems, explaining the concept of 'rem' units for responsive sizing.

Incorporating Font Awesome Icons
00:04:39

The video explains how to add scalable vector graphics (SVG) icons from Font Awesome. It details importing the Font Awesome CSS file into the document's head (via Codepen settings) and then using 'fa fa-search' and 'fa fa-times' classes to display the search and close icons respectively.

Spacing Elements with Margin
00:12:38

To add space between the input field and the icons, margin is applied to the input. The use of 'margin: 0 0.5rem 0 0.5rem;' is demonstrated to add horizontal spacing efficiently, clarifying the difference between margin and padding.

Achieving Full Width and Responsiveness
00:15:26

To make the search bar take up the full width of its container and spread the elements, 'justify-content: space-between' is applied to the 'input-wrapper'. Additionally, setting the 'input' width to '100%' ensures it fills the available space, making the search bar fully responsive. The option to set a fixed width for the 'input-wrapper' is also discussed.

Refining Input Field Styles (Border, Outline, Background)
00:18:01

Unwanted default input styles like borders and outlines are removed using 'border: none' and 'outline: none'. The 'input-wrapper' is given a background color (an orange hex code) to create the perceived single container effect. The same background color is then applied to the input field to create a seamless look.

Adding Padding, Border Radius, and Font Color
00:20:56

Padding of '0.5rem' is added to the 'input-wrapper' for internal spacing. 'border-radius: 0.5rem' is applied to give the search bar rounded corners. The font color for all elements within the 'input-wrapper' is changed to white. The placeholder text color is specifically targeted and changed using the '::placeholder' pseudo-class.

Implementing a Box Shadow
00:23:43

The final aesthetic touch is adding a box shadow to the 'input-wrapper' using the 'box-shadow' property. The tutorial explains the attributes of box-shadow: horizontal offset, vertical offset, blur radius, and color. A specific blur and offset are applied to create a distinct shadow effect, completing the visual design of the search bar.

Recently Summarized Articles

Loading...