Dr. Greg Bernstein
January 31st, 2021
Be able to change the color and size of text
Understand how fonts work on the web and be able to change fonts and create a “font stack”
Be able to style, weight, transform, and decorate text.
Differentiating elements of the same type by class
<section>
<p class="first">What color am I?</p>
<p class="second">What about me? </p>
<p class="third">And this paragraph?</p>
</section>
Using the color
property and class selectors.
<style>
.first {color: aqua;}
.second {color: green:}
.third {color: darkred;}
</style>
Renders as:
What color am I?
What about me?
And this paragraph?
Experience with fonts…
When a list of fonts is given the browser will try each name font in order to see if it is available on the system.
Using id attribute to distinguish the paragraphs.
<section>
<p id="Font1">What font is used here?</p>
<p id="Font2">What about me? </p>
<p id="Font3">And this paragraph?</p>
<p id="Font4">Finally, what about way over here?</p>
</section>
Using tag and id selectors.
section {
font-size: larger;
}
#Font1 {
font-family: sans-serif;
}
#Font2 {
font-family: "Bauhaus 93", sans-serif;
}
#Font3 {
font-family: "Courier New", monospace;
}
#Font4 {
font-family: Goudy Old Style,Garamond,Big Caslon,Times New;
font-weight: 900;
}
px (pixels): The number of pixels high you want the text to be. This is an absolute unit
1em is equal to the font size set on the parent element of the current element we are styling (more specifically, the width of a capital letter M contained inside the parent element.)
rems: These work just like ems, except that 1rem is equal to the font size set on the root element of the document (i.e. < html >), not the parent element.
<section>
<p >What font size is used here?</p>
<p class="P2">What about me? </p>
<p class="P3">And this paragraph?</p>
<p class="P4">Finally, what about way over here?</p>
</section>
html {font-size: 10px;}
section {font-size: 25px;}
.P2 {font-size: 2em;}
.P3 {font-size: 2rem;}
.P4 {font-size: 1rem;}
Used to turn italic text on and off.
Sets how bold the text is.
Allows you to set your font to be transformed. Values include:
Sets/unsets text decorations on fonts. Available values are:
You’re going to help me create examples of:
The text-align property is used to control how text is aligned within its containing content box. The available values are as follows:
The line-height property sets the height of each line of text — this can take most length and size units, but can also take a unitless value, which acts as a multiplier and is generally considered the best option.
p {line-height: 2;} /* Double spaced */
The letter-spacing and word-spacing properties allow you to set the spacing between letters and words in your text. You won’t use these very often, but might find use for them to get a certain look, or to improve the legibility of a particularly dense font. They can take most length and size units.
See the readings and references for more ways to style text!