Careeroza
Basic Selectors
Element, Class, Id and Universal
| Selector | Example | Selects |
|---|---|---|
| element | p | all <p> elements |
| .class | .intro | all elements with class="intro" |
| #id | #firstname | the element with id="firstname" |
| * | * | all elements |
| element.class | p.intro | only <p> elements with class intro |
| grouping | h1, h2, p | all h1, h2 and p elements |
Example
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
p { color: #555; }
.highlight { background: yellow; }
#main-title { color: #04AA6D; }
h2, h3 { font-family: Georgia, serif; }
</style>
</head>
<body>
<h1 id="main-title">Selectors</h1>
<h2>A heading 2</h2>
<p>A normal paragraph.</p>
<p class="highlight">A highlighted paragraph.</p>
<h3 class="highlight">Classes work on any element</h3>
</body>
</html>Result