Style any element that has a data-role attribute.
Acceptance criteria
- 1.Style any element that has a data-role attribute.
CSS Tutorial · CSS Selectors
These 10 tasks go with the CSS Attribute Selectors chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “CSS Attribute Selectors are used to select HTML elements based on their attributes or attribute values.” .
1.Match attribute presenceexercise · easy · 10 min
Style any element that has a data-role attribute.
Passes when: Style any element that has a data-role attribute.
2.Match an exact valueexercise · easy · 10 min · practice plan
Style elements whose data-role is exactly primary.
Passes when: Style elements whose data-role is exactly primary.
3.Match a prefixexercise · easy · 10 min · practice plan
Style elements whose data-role starts with "prim".
Passes when: Style elements whose data-role starts with "prim".
4.Match a suffixexercise · easy · 10 min · practice plan
Style elements whose data-role ends with "ary".
Passes when: Style elements whose data-role ends with "ary".
5.Match a substringexercise · medium · 10 min · practice plan
Style elements whose data-role contains "rima".
Passes when: Style elements whose data-role contains "rima".
6.Fix the missing bracketsbug fix · easy · 8 min
Attribute selectors need square brackets.
Passes when: Attribute selectors need square brackets.
7.Fix the wrong attribute valuebug fix · easy · 8 min · practice plan
The value in the selector does not match the markup.
Passes when: The value in the selector does not match the markup.
8.Fix the prefix operatorbug fix · easy · 8 min · practice plan
A prefix match uses ^=, not =^.
Passes when: A prefix match uses ^=, not =^.
9.Fix the suffix operatorbug fix · easy · 8 min · practice plan
^= matches the start of the value; a suffix match needs $=.
Passes when: ^= matches the start of the value; a suffix match needs $=.
10.Fix the unquoted value with a dashbug fix · easy · 8 min · practice plan
Values containing dashes must be quoted.
Passes when: Values containing dashes must be quoted.
Between them these tasks cover Attribute presence and Exact and partial matches.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.