Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

8. Getting Started with CSS: Adding a Li... > Creating a selector for the class

Creating a selector for the class

To select a class, you write the selector like this:

image with no caption

So now you have a way of selecting <p> elements that belong to a certain class. 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;  
}                   

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial