liveBook · Manning

CSS selector

As explained in WordPress Power Toolkit: Harness AI to build next-level websites

A CSS selector is a pattern that identifies the HTML elements to which a CSS rule applies.

A CSS selector is the part of a CSS rule that names the HTML element or design element to style. It comes before curly braces, followed by property/value pairs such as color or font size. An element name like h1 can be a selector, and a class name can be one too. section 7.2 section 7.3

Use lowercase consistently in HTML and CSS names. Case differences can make apparently similar names into different selectors, causing a style not to apply as expected. section 7.2

Reuse a class style

A class selector lets one style serve many elements. Define a class such as .greensans once, then add class="greensans" to headings or paragraphs. Later changes to the class definition update every element using that class, avoiding repeated inline style attributes. section 7.6

Try selectors in a practical website-editing workflow:

  • Add a class rule in Appearance > Customize > Additional CSS, then publish it. section 7.6
  • Add the class name to the relevant page HTML, update the page, and view the result. section 7.6
  • Use the browser Inspector to select an element and read the rules applied to it, including rules overridden lower in the cascade. section 7.3
  • Live-edit, disable, or add rules in the Inspector to test visual changes; these experiments do not permanently change the stylesheet. section 7.3
.greensans {
  color: green;
  font-family: sans-serif;
}

This class rule shows a selector beginning with a dot and the reusable color and font declarations it controls. section 7.6

Finding a selector for a date stamp

To hide a post date, select the date in YellowPencil, open its CSS Editor with E, and copy the generated selector into Additional CSS. Selector words vary by site, so use the selector shown for the actual date element rather than assuming an example will match. section 9.5

How WordPress Power Toolkit: Harness AI to build next-level websites covers it

How deep it goes
Defines rule syntax and element and class selectors, then demonstrates live inspection while deferring other selector kinds.
Examples
Uses h1 rules, reusable greensans classes, and a generated selector for hiding blog-post dates.
What it assumes
Teaches selector basics through examples while assuming access to WordPress customization and browser inspection tools for guided tasks.
What you can do after
Operate/configure it to apply reusable class styles and inspect or test page styling.
How it connects
Connects CSS rules, HTML elements, classes, the Inspector, and the CSS cascade.

Also explained in

Compare how 8 books explain CSS selector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of WordPress Power Toolkit: Harness AI to build next-level websites. The section links point to the parts of the book it draws on.