HTML and CSS Reference
In-Depth Information
Creating a class selector
To create a class in CSS and select an element in that class, you write a
class selector
, like this:
Then u
se a “.” to
specify
a class.
p.greentea {
color: green;
}
So now you have a way of selecting
<p>
elements that belong to a certain class to
style them. All you need to do is add the
class
attribute to any
<p>
elements you
want to be green, and this rule will be applied. Give it a try: open your “lounge.css”
file and add the
p.greentea
class selector to it.
body {
font-family: sans-serif;
}
h1, h2 {
color: gray;
}
h1 {
border-bottom: 1px solid black;
}
p {
color: maroon;
}
p.greentea {
color: green;
}