The Basics: Element, ID, and Class
Select all instances of a given element
<div>
<p>You say yes</p>
<p>I say no</p>
</div>
<div>
<p>You say goodbye</p>
<p>I say hello </p>
</div>
div{
background: purple;
}
p {
color: yellow;
}
Selects an element with a given ID. Only one per page!
<div>
<p>You say yes</p>
<p>I say no</p>
</div>
<div>
<p>You say goodbye</p>
<p id="special">I say hello </p>
</div>
div{
background: purple;
}
#special {
color: yellow;
}
Selects all elements with a given class
<div>
<p class="highlight">You say yes</p>
<p>I say no</p>
</div>
<div>
<p class="highlight">You say goodbye</p>
<p>I say hello </p>
</div>
div{
background: purple;
}
.highlight {
background: yellow;
}