Menu
CoddyTech

Row State Presentation

Part of the Responsive UI Patterns section of Coddy's Tailwind CSS journey. Lesson 23 of 55.

Alternating row backgrounds help readers follow a line of data. odd: and even: count sibling positions, so put them on body rows inside tbody. A separate header section does not alter the body’s first-child position.

<tr aria-selected="true" class="odd:bg-[#e2e8f0] even:bg-white aria-selected:font-semibold"><td>Selected studio</td></tr>

The example gives odd rows a light gray stripe. Selection is a different concept: the built-in aria-selected: variant matches aria-selected="true". Supplied application behavior owns that attribute; CSS presents it.

A selected row should have a distinguishable cue and return to its original stripe after deselection. Arbitrary hexadecimal background utilities can specify exact exercise colors, such as bg-[#e2e8f0]. Test selection on both odd and even rows.

challenge icon

Challenge

Medium

Stripe odd body rows with #f1f5f9 and even rows white. Give the row whose supplied aria-selected state is true a #dbeafe background. The supplied button moves selection and must restore each deselected row’s original stripe. Preserve all table semantics.

Preserve the supplied content, semantic elements and IDs. Edit the requested utility classes. Press Run preview after edits, then Check/Run code to grade the result. Supplied JavaScript is read-only.

Try it yourself

<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<table id="table" class="w-96"><caption>Studio schedule</caption><thead><tr><th scope="col" class="">Session</th><th scope="col" class="">Room</th></tr></thead><tbody><tr id="r1" class="bg-white"><th scope="row">Session 1</th><td id="cell1">Room 1</td></tr><tr id="r2" class="bg-white"><th scope="row">Session 2</th><td id="cell2">Room 2</td></tr><tr id="r3" class="bg-white"><th scope="row">Session 3</th><td id="cell3">Room 3</td></tr></tbody></table><button id="switch">Move selection</button>
<script src="./controls.js"></script>
</body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Responsive UI Patterns