Problem: Custom Checkbox Control
Problem description
Given an HTML page containing a label with the class .custom-checkbox that wraps a native checkbox input, a span element with class .checkmark, and the text “Subscribe to newsletter”, write CSS to:
Hide the native checkbox input.
Style the
.checkmarkas a20×20 pxsquare with a2pxsolidborderand a slightborder-radius.Use
::afteron.checkmarkto draw a tick mark when the checkbox is checked.Change the
background-colorof the box to#2196F3when:checked.
Goal
Write the necessary CSS rules so that the .custom-checkbox displays a square "checkbox" that fills with color and shows a white tick when selected.
Constraints
Use only CSS (no JavaScript).
Checkmark box size should be
20pxby20px.Bordershould be2px solid #666,border-radiusshould be4px.Checked
background-colorshould be#2196F3.Tick mark should be white, drawn via
::after, sized and positioned appropriately.
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 Checkbox Control
Problem description
Given an HTML page containing a label with the class .custom-checkbox that wraps a native checkbox input, a span element with class .checkmark, and the text “Subscribe to newsletter”, write CSS to:
Hide the native checkbox input.
Style the
.checkmarkas a20×20 pxsquare with a2pxsolidborderand a slightborder-radius.Use
::afteron.checkmarkto draw a tick mark when the checkbox is checked.Change the
background-colorof the box to#2196F3when:checked.
Goal
Write the necessary CSS rules so that the .custom-checkbox displays a square "checkbox" that fills with color and shows a white tick when selected.
Constraints
Use only CSS (no JavaScript).
Checkmark box size should be
20pxby20px.Bordershould be2px solid #666,border-radiusshould be4px.Checked
background-colorshould be#2196F3.Tick mark should be white, drawn via
::after, sized and positioned appropriately.
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.