On this page
  1. Basic & Combinator Selectors
  2. Contents
  3. Basic Selectors
  4. Attribute Selectors
  5. Combinators

Basic & Combinator Selectors

Prev: selectors | Up: selectors | Next: Pseudo-Classes
Rel: Cascade, Specificity & Inheritance, Global Attributes
Ref: MDN Web Docs — CSS Selectors
Tags: #public #web #css #selectors


Contents


Basic Selectors


Attribute Selectors

a[target="_blank"]     { text-decoration-style: dashed; }
a[href^="https://"]    { font-weight: 500; }  /* starts with */
img[src$=".svg"]       { height: auto; }      /* ends with */
[data-state~="open"]   { display: block; }    /* whitespace-separated word */

Combinators

nav a          { color: inherit; }   /* Descendant */
ul > li        { margin-block: 4px; } /* Direct child */
h2 + p         { margin-top: 0; }    /* Next sibling */
h2 ~ p         { color: #444; }      /* Subsequent siblings */

Linked from

Related notes