Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Working with Class

While divs and ids are useful in organizing the structure of a web page, the class attribute is useful when you want to create a style that can be applied across several tags in a document. For example, you might want to have certain sections of your text called out in different colors from the rest of the text in the document. If ZwiftBooks wanted to use a special background to highlight special content, for example, Wilma could create a single style in her CSS, something like this:

.bluebkgnd {background-color: #0000ff;}

This syntax, with the dot (.) preceding the name bluebkgnd, creates a class called bluebkgnd, which can be applied to any HTML element for which we want a blue background. Making the connection in the HTML is as simple as adding a class attribute to any element, such as this one:

<h1 class="bluebkgnd">...

or this one:

<p class=" bluebkgnd ">...
  • + Share This
  • 🔖 Save To Your Account