Problem: Custom Search Input Control
Problem description
Given an HTML page containing a div with class search-wrapper that wraps an <input type="search" class="custom-search" placeholder="Search...">, write CSS to:
Remove native search decorations and clear button using WebKit pseudo-elements:
::-webkit-search-decoration::-webkit-search-cancel-button::-webkit-search-results-button::-webkit-search-results-decoration
Style
.search-wrapperwithposition: relativeanddisplay: inline-block.Use
.search-wrapper::beforeto display a magnifier icon (content: “🔍”) positioned atleft: 0.5rem, vertically centered, non-interactive, withfont-size1remandcolor#666.Style
.custom-searchas follows:Initial
widthshould be200px;heightshould be2rem.Padding should be
0 1rem 0 2rem(space for icon).Border should be
1px solid #ccc;border-radiusshould be4px.Transitions should be
width 0.3s easeandborder-colorshould be0.2s ease.Hide default appearance with
-webkit-appearance: none.
On
.custom-search:focus, expandwidthto300px, changeborder-colorto#0066cc, and removeoutline.Style
.custom-search::placeholdercolorto#999.
Goal
Write CSS rules so the search input shows a custom magnifier icon inside it, hides native decorations, smoothly expands on focus, and has styled placeholder text.
Constraints
Use only CSS (no JavaScript).
Ensure the icon pseudo-element does not capture pointer events.
Apply transitions only on
widthandborder-color.Style placeholders using the
::placeholderpseudo-element.Limit vendor-specific pseudo-elements to WebKit.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.
Problem: Custom Search Input Control
Problem description
Given an HTML page containing a div with class search-wrapper that wraps an <input type="search" class="custom-search" placeholder="Search...">, write CSS to:
Remove native search decorations and clear button using WebKit pseudo-elements:
::-webkit-search-decoration::-webkit-search-cancel-button::-webkit-search-results-button::-webkit-search-results-decoration
Style
.search-wrapperwithposition: relativeanddisplay: inline-block.Use
.search-wrapper::beforeto display a magnifier icon (content: “🔍”) positioned atleft: 0.5rem, vertically centered, non-interactive, withfont-size1remandcolor#666.Style
.custom-searchas follows:Initial
widthshould be200px;heightshould be2rem.Padding should be
0 1rem 0 2rem(space for icon).Border should be
1px solid #ccc;border-radiusshould be4px.Transitions should be
width 0.3s easeandborder-colorshould be0.2s ease.Hide default appearance with
-webkit-appearance: none.
On
.custom-search:focus, expandwidthto300px, changeborder-colorto#0066cc, and removeoutline.Style
.custom-search::placeholdercolorto#999.
Goal
Write CSS rules so the search input shows a custom magnifier icon inside it, hides native decorations, smoothly expands on focus, and has styled placeholder text.
Constraints
Use only CSS (no JavaScript).
Ensure the icon pseudo-element does not capture pointer events.
Apply transitions only on
widthandborder-color.Style placeholders using the
::placeholderpseudo-element.Limit vendor-specific pseudo-elements to WebKit.
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.