B.1. Selector Examples
The following table should be used as a quick reference of CSS selector syntax. For more on selectors, see Chapter 13 and the end of this appendix.
Type of Selector | Example | Sample Match (matched tag in bold for reference) |
---|---|---|
By name | h1, h2, h3 | <h2> |
By class | .booktitle | <span class="booktitle"> |
By id | div#logo | <div id="logo"> |
By any attribute | acronym[title] | <acronym title="Ta Ta For Now"> |
As child | div > p | <div><p> |
As grandchild or deeper | div * p | <div><form><p> |
As child, grandchild, or deeper | div p | <div><p> |
As sibling </th><td> | th + td | <tr><th scope="row">... |
Pseudo-class | :visited | <a> (after being visited) |
Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.