CiTi · Computer Coding · Year Two · Unit 1
A lesson within “Building Data-Driven Applications”
What tools can I use to streamline the process?
Every data-driven application starts with a form: it is where a user’s choice becomes data. Today’s tool is CSS itself. Browsers draw form controls their own way, but a handful of advanced selectors let a developer design data-entry forms that match any site, with no JavaScript and no extra plugins.
Demonstrate proficiency with:
Managing Data-Driven Application Abilities Backend Administration Design & DevelopmentHands-On:
#2 Style with CSS
#7 Validate and debug my own work
Professional:
#5 Work through ambiguity
#7 Treat a mistake as data, not failure
Geometry and measurement: centering a 15px dot inside a 25px ring ((25 − 15) ÷ 2 = 5px), and adding padding, height, and margin to keep every row the same height. Logical ordering: a rule that can only reach elements that come after a given element, and a scoring system (specificity) that decides which of two matching rules wins.
Reverse-engineering a finished product from a short technical brief, the way developers rebuild a client’s mockup. Testing beyond the happy path (keyboard as well as mouse) and comparing one’s own work against a reference without simply copying it.
Hiding a native radio button while keeping it usable, drawing a replacement control with an empty element and ::before, styling checked and hover states with :checked, :hover, the adjacent sibling +, general sibling ~, descendant, and attribute selectors, positioning with relative/absolute and z-index, and reading selector specificity.
Students will understand how advanced CSS selectors let a hidden form control drive the look of other elements: and will build a fully custom radio-button form that still works by mouse and keyboard, then explain why each selector and positioning rule is needed.
opacity: 0 instead of display: none, and how its label still picks it.div, border-radius, and ::before with content: ''.:checked + label and :checked ~ .check, and explain why the circle needs ~ but the label can use +.position: relative and absolute, and use z-index so clicks on the circle still work.Students rebuild a finished design from a one-paragraph brief and a list of required techniques, the same way a developer rebuilds a designer’s mockup. Push further: use the technique on the data-entry form of the student’s own Unit 1 project (for example, a status or category choice in the Student Project System or Material Inventory System) styled to that project’s look, moving toward “Realistic Industry Task.”
This is an example of what you can do with pure CSS to style radio buttons or checkboxes. You will need to use a variety of CSS techniques: ::before, input[type=????], the descendant selector (space), the child selector (>), the adjacent sibling selector (+), the general sibling selector (~), position, and z-index.
One form, one heading, one list. Every option is an <li> holding exactly three things, in this order:
name on every radio makes them one group, so only one can be picked, and the form sends fave=pizza.for matches id exactly, capital letters included.The form’s action is [thisurl], a WebDNA tag that submits the form back to the same page, so students can press Save and see what the form sends in the address bar.
CSS can barely change a native radio button. So the solution hides it and draws a new circle with a plain <div>. The hidden radio still does all the real work: it gets clicked through its label, remembers the choice, and sends the value. Its :checked state is what restyles the fake circle and the label.
| Selector | In plain English |
|---|---|
| input[type=radio] | Attribute selector: only radios, not the submit button (also an <input>) |
| ul li | Descendant (space): any li inside a ul |
| input[type=radio]:checked + label | Adjacent sibling: the label immediately after a checked radio |
| input[type=radio]:checked ~ .check | General sibling: the circle anywhere after a checked radio in the same li (it skips over the label) |
| .check::before | Pseudo-element: the inner dot, created with no extra HTML |
| li:hover label | The label inside the row under the mouse; hovering the whole row reacts, circle included |
| ul > li | Child: only lis directly inside the ul. In the brief, but not needed here, since there are no nested lists and ul li does the same job. |
Each li gets position: relative, so each .check with position: absolute; top: 30px; left: 20px is placed inside its own row. Without it, all four circles are placed against the page and pile up in one spot.
The circle overlaps the label’s left padding. With no z-index, the element later in the HTML (the .check div) is drawn on top and swallows clicks. z-index: 1 on the label lifts it above; it has no background, so the circle still shows through.
opacity: 0 hides it from the eyes only: Tab and arrow keys still work and the value still submits. display: none would remove it for keyboard users.
input[type=radio]:checked + label scores (0, 2, 2) and beats li:hover label at (0, 1, 2), so a checked option stays green when hovered. The checked rule sets no padding, so the hover padding still slides it right.
| What students see | Usual cause (walkthrough step) |
|---|---|
| The font is plain, not Lato | @import is not the first line of the stylesheet; the browser silently skips it (step 1) |
| All circles piled in one spot | li is missing position: relative (step 2) |
| Default browser radios still showing | Selector typo (no spaces inside input[type=radio]) or missing opacity: 0 (step 4) |
| Ring turns green but no center dot | .check::before is missing content: ''; (step 6) |
| Circle and label don’t both light up | Wrong order inside the li: must be input, label, then .check (steps 0 and 7) |
| Clicking right on a circle does nothing | Label is missing z-index: 1 (step 8) |
| Clicking a word doesn’t pick it | for and id don’t match exactly, often a capital letter (step 0) |
| More than one option can be picked | Radios have different name values (step 0) |
The walkthrough’s Fix It section lists these same symptoms for students. Point them there before answering.
| Time | Phase | What happens |
|---|---|---|
| 5 min | Warm-Up / Hook | Show a plain browser radio list next to the finished example. Students click and hover the example. Ask: “Can CSS restyle that little gray circle? Make a guess how this was built.” |
| 10 min | Direct Instruction | Hand out the brief. Walk the HTML structure and why the input comes first. Introduce + vs. ~, attribute selectors, and ::before with one-line demos in DevTools. Do not show the full solution. |
| 10 min | Guided Practice | Together: page setup, list cleanup, and turning labels into full-row click targets (walkthrough steps 1 through 3). Stress position: relative on the li and say it will matter later. |
| 25 min | Independent Practice | Students hide the radio, draw the circle and dot, and attempt the checked state on their own, using the brief’s technique list. Circulate with the Teacher Watch List. |
| 5 min | Check-In | Quick poll: who has a circle, who has a dot, who has a working checked state. Students note their biggest blocker for tomorrow. |
| Time | Phase | What happens |
|---|---|---|
| 5 min | Warm-Up | Project a broken version where clicking the circle does nothing. Pairs guess why (the z-index problem, step 8). |
| 15 min | Independent Practice | Finish the checked state, hover effects, and submit button. Press Save and read fave=... in the address bar. |
| 15 min | Compare & Fix (pairs) | Release the Solution Walkthrough. Pairs run the Compare Your Work checklist on each other’s forms, including the keyboard test (Tab and arrow keys). Use Fix It to repair differences in their own code rather than pasting the full solution. |
| 10 min | Direct Instruction: Specificity | Hover the checked option: why does it stay green? Score li:hover label (0, 1, 2) against :checked + label (0, 2, 2) as a class. Note where a transition lives decides whether it animates both ways. |
| 10 min | Closure & Exit Ticket | Students answer the walkthrough’s Check Yourself questions in their heads, then complete the exit ticket. |
Formative: Pair check against the walkthrough’s Compare Your Work list: Lato font loaded, no default radios showing, clicking a word or a circle picks one option only, checked option shows a thick green ring with a green dot and big green text, hover slides and recolors rows, hovering the checked row keeps it green, the Save button fades on hover, and Tab plus arrow keys still change the choice.
Exit ticket (completion-graded): “Explain why the circle uses ~ but the label can use +. Then explain what would break if the input came after the .check div.”
Extension: (1) Build a checkbox version: input[type=checkbox], unique name values, and a rounded-square .check. (2) Add a visible keyboard focus style with input[type=radio]:focus-visible ~ .check, so keyboard users can see which option they are on. (3) Restyle the form to match the student’s own Unit 1 project.