untitled

(John Hannent) #1

Specifying All-Purpose Properties ..............................................................


You don’t always have to attach a class to a tag. You can specify a generic
class that can be applied to anykinds of tags in the HTML code. This way,
you can avoid having to assign, say, a specific blue color value to each tag
that you want to display in blue. You can just assign the blue class whenever
you want some element to be blue. (This saves time because styles can be
complicated and lengthy, and you only have to specify a CSS rule once.
Thereafter in the HTML code, merely use the rule’s class name instead of
having to repeat all the properties and values in the rule.)

For example, if you want to be able to turn any kind of text blue to highlight
it, leave out the selector name, omit the pin p.blue {color: blue}when
you define the “highlight” class in the CSS file. The following is a generic class
definition of blue:

/* This class can be used with any HTML tag */

.highlight {color: blue;}

Now, anyHTML element that uses class = highlightturns blue:

<html>
<head>

<link type=”text/css” rel=”stylesheet” href=”ParaStyle.css”>
</head>

<body>

<p class=”highlight”>
I’m blue body text.
</p>

<h2 class=”highlight”>
I’m a BLUE HEADLINE
</h2>

</body>
</html>

If you want to make only part of a paragraph blue, use the <span>tag, like this:

<p>I say again, <span class=”highlight”>and I use blue for
emphasis here</span> that you need to remember the
lesson plans</p>

Chapter 2: Getting Results with CSS 37

Free download pdf