HTML selectors simply specify an HTML element to which the declarations should
be applied, so
h2 { color: red; }
Will make all h2 HTML elements red.
id selectors attach styles to the HTML element with that corresponding id. So, if
you had something like this in your HTML:
<h2 id=”tree”>Tree</h2>
And you just wanted to apply styles to that element, you would do this (note the #
character at the start of the selector):
#tree { color: red; }
class selectors attach styles to HTML elements with a corresponding class. So, if
you had something like this in your HTML:
<h2 class=”plant”>Tree</h2>
And you wanted to apply styles to that element and every other element with
class=”plant”, you would do this (note the dot at the start of the selector):
.plant { color: red; }
You can attach a number of classes to an HTML element by separating them with
spaces, such as:
<h2 class=”plant leafy”>Tree</h2>
Which will apply both of these rules:
.plant { color: red; }
.leafy { font-style: italic; }
0 comments:
Post a Comment