Skip to main content
CSS-Tricks
  • Articles
  • Notes
  • Links
  • Guides
  • Almanac
  • Shuffle
Search

Articles Tagged
selectors

16 Articles
{
,

}
Direct link to the article CSS Selectors
selectors

CSS Selectors

A complete guide covering all of the various methods we have to select elements in CSS and how to use them for applying styles.
Avatar of Geoff Graham
Geoff Graham on Jul 15, 2024 (Updated on Jul 23, 2024)
Direct link to the article “If” CSS Gets Inline Conditionals
custom properties selectors

“If” CSS Gets Inline Conditionals

A few sirens went off a couple of weeks ago when the CSS Working Group (CSSWG) resolved to add an if() conditional to the CSS Values Module Level 5 specification. It was Lea Verou’s X post that same day that …

Avatar of Geoff Graham
Geoff Graham on Jul 9, 2024 (Updated on Jul 19, 2024)
Direct link to the article Case-Sensitive Selectors
selectors

Case-Sensitive Selectors

/* Case sensitive */
a[href*='css-tricks' s] {}

/* Case insensitive */
a[href*='css-tricks' i] {}

Adding an s makes the selector case-sensitive and i makes it case-insensitive.

Source…
Avatar of Geoff Graham
Geoff Graham on May 22, 2024
Direct link to the article @supports selector()
:where @supports cross-browser selectors

@supports selector()

I didn’t realize the support for @supports determining selector support was so good! I usually think of @supports as a way to test for property: value pair support. But with the selector() function, we can test for selector support …

Avatar of Chris Coyier
Chris Coyier on Oct 19, 2021
Direct link to the article You want enabling CSS selectors, not disabling ones
margin selectors

You want enabling CSS selectors, not disabling ones

I think this is good advice from Silvestar Bistrović:

An enabling selector is what I call a selector that does a job without disabling the particular rule.

The classic example is applying margin to everything, only to have to remove …

Avatar of Chris Coyier
Chris Coyier on Aug 31, 2021 (Updated on Sep 1, 2021)
Direct link to the article CSS Vocabulary
selectors terminology

CSS Vocabulary

This is a neat interactive page by Ville V. Vanninen to reference the names of things in the CSS syntax. I feel like the easy ones to remember are “selector,” “property,” and “value,” but even as a person who writes …

Avatar of Chris Coyier
Chris Coyier on Jul 27, 2020
Direct link to the article A Use Case for a Parent Selector
parent selectors selectors

A Use Case for a Parent Selector

Having a “parent selector” in CSS is mentioned regularly as something CSS could really use. I feel like I’ve had that thought plenty of times myself, but then when I ask my brain for a use case, I find it …

Avatar of Chris Coyier
Chris Coyier on Dec 31, 2019 (Updated on Mar 5, 2021)
Direct link to the article Could Grouping HTML Classes Make Them More Readable?
classes HTML selectors semantics

Could Grouping HTML Classes Make Them More Readable?

You can have multiple classes on an HTML element:

<div class="module p-2"></div>

Nothing incorrect or invalid there at all. It has two classes. In CSS, both of these will apply:

.module { }
.p-2 { }
const div = document.querySelector("div");
…
Avatar of Chris Coyier
Chris Coyier on Apr 22, 2019
Direct link to the article CSS Selectors are Conditional Statements
selectors

CSS Selectors are Conditional Statements

.foo {

}

Programmatically, is:

if (element has a class name of "foo") {

}

Descendent selectors are && logic and commas are ||. It just gets more complicated from there, with things like combinators and pseudo selectors. Just …

Avatar of Chris Coyier
Chris Coyier on Dec 6, 2018
  • 1
  • 2
  • Older

CSS-Tricks is powered by DigitalOcean.

Keep up to date on web dev

with our hand-crafted newsletter

DigitalOcean
  • About DO
  • Cloudways
  • Legal stuff
  • Get free credit!
CSS-Tricks
  • Write for us!
  • Advertise with us
  • Contact us
Social
  • RSS Feeds
  • CodePen
  • Mastodon
  • X
Back to Top