Up to this point, we've used CSS to select an HTML element by its tag name only. However, we can use class selectors to target classes of HTML elements.
Consider the HTML below:
div is the parent element and the
p are children. CSS styles applied to the
header class selector will automatically apply to the
h2 and the
Here's a refresher on parent and child elements.
In CSS, class selectors can be identified by a dot
. followed by the class name, as seen below:
As a result of this code, child elements of divs with the
header class will have a font color of
Below, we will use a CSS class selector to style more than one HTML element at once.