HTML CSS Exercise: Select elements by attribute
Solution:
HTML Code:
Explanation:
- The HTML document consists of two <div> elements with the class 'container'.
- The first <div> has an additional attribute data-name set to "w3r".
- CSS styling is applied within <style> tags.
- The .container[data-name=w3r] selector targets elements with class 'container' and attribute 'data-name' equal to 'w3r'.
- It sets the text color of these elements to a shade of blue (#5ac4ed).
- The second <div> does not have the specified attribute, so it does not match the CSS selector and remains unaffected by the styling.
Live Demo:
Supported browser
![]() |
![]() |
![]() |
![]() |
![]() |
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.