Summary
Uses classes to give multiple items on a page the same look.
Situation
You want to make several items on a page have the same look.
Action
- Add the
classattribute to tags you want to look the same. Make up a class name. - Define the class in a stylesheet.
For example, here are ps with different classes.
- <!doctype html>
- <html lang="en">
- <head>
- <title>Cattos</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <link rel="stylesheet" href="cattos.css">
- </head>
- <body>
- <h1>Cattos</h1>
- <p class="fact">Most cattos are cuddly.</p>
- <p class="fact">Cattos and doggos usually get along.</p>
- <p class="not-fact">Cattos are evil.</p>
- <p class="fact">Doggos are better, but cattos are OK.</p>
- <p class="fact">Cattos like laser pointers.</p>
- <p class="not-fact">Cattos have flippers.</p>
- </body>
- </html>
In cattos.css:
- body {
- font-family: sans-serif;
- background-color: antiquewhite;
- }
- .fact {
- color: darkgreen;
- font-style: italic;
- }
- .not-fact {
- color: darkred;
- font-weight: bold;
- }
Where referenced