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
- Type:
article,button— Specificity(0, 0, 1) - Class:
.card,.is-active— Specificity(0, 1, 0) - ID:
#main-nav— Specificity(1, 0, 0) - Universal:
*— Specificity(0, 0, 0)
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
- tuts/css/selectors Linked here; links to this page; shared tags: #css, #selectors, #web
- tuts/css/selectors/pseudo_classes Linked here; links to this page; shared tags: #css, #selectors, #web
- tuts/html/attributes/global_attributes Linked here; links to this page; shared tags: #web
- tuts/css/tutorials/cascade_specificity_and_inheritance Linked here; shared tags: #css, #web
- tuts/html/attributes links to this page; shared tags: #web
- tuts/html/elements links to this page; shared tags: #web
- tuts/css/selectors/pseudo_elements shared tags: #css, #selectors, #web
- tuts/css shared tags: #css, #web
- tuts/css/at_rules shared tags: #css, #web
- tuts/css/at_rules/keyframes_and_fonts shared tags: #css, #web