The CSS Class Selector

How do we specify an class selector?

Class selectors let you assign styles in a way that is independent of document elements.
These selectors can be used on their own or in conjunction with type selector.

You use class selectors in your web pages by giving the class attribute
for the appropriate html elements the name of the class selector.

.className {color:red; font-size:12px; line-height:15px;}
/* For a class selector that is independent of document elements
you only start with a dot and then the name of the class.*/
elementName.className {color:red; font-size:12px; line-height:15px;}
/* If you would like the class selector to be
related to an html element you need to provide the name of html element,
followed by a dot and then the name of the class selector.*/

Of course, you can create a descendant selector or a child selector that
is a mix of a class selector and a type selector.

div p.myclass {color:red; font-size:12px;}

With this CSS rule in effect, any HTML code containing an p element with attribute class='myclass'
inside an div element on the web page is automatically
rendered in 12-pixel font-size type and colored red.

div>p.myclass {color:red; font-size:12px;}

With this CSS rule in effect, any HTML code containing an p element with attribute class='myclass'
as direct child element inside an div element on the web page is automatically
rendered in 12-pixel font-size type and colored red.