p {color: green; font-style: italic;}
wouldn't work because it would render all your paragraphs with a green italic font. Not what you want, right? Well here's how to fix that....GreenItalic {
color: green;
font-style: italic;
}
color: green;
and font-style: italic;
to apply, you guessed it, green colored text with an italic font style. You would then insert the above into an embedded or external style sheet. Now to get any HTML element to use this class, all we have to do is apply the class
attribute and use the name we selected as the value. <p class="GreenItalic">It was a dark and stormy night.</p>
GreenItalic
class in first two paragraphs but not the third:<html>
<head>
<title></title>
<style type="text/css">
<!--
.GreenItalic {
color: green;
font-style: italic;
}
-->
</style>
</head>
<body>
<p class="GreenItalic">Text rendered in green italic font.</p>
<p class="GreenItalic">Text rendered in green italic font.</p>
<p>Text NOT rendered in green italic font.</p>
</body>
</html>
class
attribute and your embedded or external style sheet. GreenItalic
class could also be used in an h1
element, a span
element or a div
element. This makes classes versatile and reusable so remember to economize whenever you can otherwise you'll end up with humongous style sheets. GreenItalic
as a selector in your style sheet, using class="greenitalic"
in your HTML code won't work. It has to be class="GreenItalic"
Free Text Editors
Free Graphics Editors
Website Analysis Tools
Free Website Templates
See also:
Best Free Web Hosting
How to Make a Web Page
If you need a .COM web address, you can get one quick and easy at...
<~ BACK | TOP | NEXT ~> |