CSS Attribute Selectors
- You can target elements by whether or not they have specific attributes or whether those attributes have certain values.
- We can also do some pattern matching on the attribute values.
- We use square brackets to contain the attribute names and/or values
p[title]{
/* target paragraphs that has a title attribute */
}
a[href="#"]{
/* targets anchors that have an href whose value is "#" exactly */
}
img[src^="https://"]{
/* targets images whose src attribute starts with "https://"
}
- CSS Tricks has a great article on the different types of attribute selectors
- CSS-Tricks tutorial on attribute selectors