Problem: Segmented Control Toggle
Problem description
Given an HTML page containing a div with class segmented-control that wraps three pairs of radio inputs (name=“segment”) and their corresponding labels (e.g., Option 1, Option 2 , and Option 3), write CSS to:
Hide the native radio inputs.
Display the
.segmented-controlas a horizontalflexcontainer.Style each
labeltoflexequally,centertext, addpadding, and a1px solid #cccborder.Remove the right
borderon all labels except the last.Apply a
4pxborder-radiusto the first and last labels (outer corners).Change the
background-colorto#0066ccand text color to#ffffor thelabelimmediately following acheckedinput.Include smooth transitions (
0.2s ease) forbackground-colorandcolorchanges.
Goal
Write the CSS rules to render a three-segment toggle where clicking a segment highlights it in blue with white text, while the others remain with a white background and gray border.
Constraints
Use only CSS (no JavaScript).
There should be equal width segments via
flex: 1on labels..segmented-controlshould not overflow its container.Use adjacent sibling selectors (
input:checked + label) andlabelpseudo-class selectors (:first-of-typeand:last-of-type).Transitions should be
background-color 0.2s easeandcolor 0.2s ease.
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: Segmented Control Toggle
Problem description
Given an HTML page containing a div with class segmented-control that wraps three pairs of radio inputs (name=“segment”) and their corresponding labels (e.g., Option 1, Option 2 , and Option 3), write CSS to:
Hide the native radio inputs.
Display the
.segmented-controlas a horizontalflexcontainer.Style each
labeltoflexequally,centertext, addpadding, and a1px solid #cccborder.Remove the right
borderon all labels except the last.Apply a
4pxborder-radiusto the first and last labels (outer corners).Change the
background-colorto#0066ccand text color to#ffffor thelabelimmediately following acheckedinput.Include smooth transitions (
0.2s ease) forbackground-colorandcolorchanges.
Goal
Write the CSS rules to render a three-segment toggle where clicking a segment highlights it in blue with white text, while the others remain with a white background and gray border.
Constraints
Use only CSS (no JavaScript).
There should be equal width segments via
flex: 1on labels..segmented-controlshould not overflow its container.Use adjacent sibling selectors (
input:checked + label) andlabelpseudo-class selectors (:first-of-typeand:last-of-type).Transitions should be
background-color 0.2s easeandcolor 0.2s ease.
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.