- CSS specifies sizes in several places. These need units, of
which CSS has many.
Just a few:
- Absolute units are allowed on a screen, but really only meaningful when
a page is printed.
- Pixel, px. Being called pixel, one would expect
some relation to the little colored dots on the screen, but the
standard says it's just 1/96 of an inch. Go figure.
- Point, pt. It is 1/72 of an inch, a traditional unit in
printing.
- in, cm, mm and several others.
- Font-relative units
- em, ex, the width of the letter m or x
in the current font, so they adjust with context (current font size).
- rem, rex, the same, for the font size at the root element.
- lh, rlh, the line height at the current location, or for
the root element.
- Display-relative units
- vh and vw each represent 1% of the
viewport (browser window) height and width, respectively.
- vmin and vmax are the smaller and larger of
vh and vw.
- There are several other versions to deal with optimizaions used
for phone screens and other things. We'll skip that, I'm afraid.
- Percent, %.
- When applied to a font, it is relative to
the normal font size.
- When applied to anything else, it is relative
to the same dimsion of its container.
- If your only container is the page, you are much better off using
vh and vw. Percentage sizes work for boxes which are
inside others.
[ Dimensions Source ]
- CSS Colors. CSS has many ways of
specifying them.
- CSS defines several hundred colors
by
name. Welcome to the Internet paint store: darkred,
gold, midnightblue, sandybrown, etc.
- Colors on a computer screen:
- Represented by three numbers, indicating
the amount of each primary color: red, green and blue.
- Conventionally, each amount is given by an unsigned byte.
That means a range 0–255.
- In hexadecimal (base 16), that is 00–FF.
- 00 = 0, 01 = 1, …, 09 = 9, 0A = 10, … 0F = 15, 10 = 16, …
1E = 30, 1F = 31, 20 = 32, …, 7F = 127, 80 = 128, …, FF = 255.
- Can specify a color by six hexadecimal digits run together, giving
the amount for red, green and blue.
#000000, #A34491, #1256AB, #55BB33,
#BBBB55, #555555
- Can alternatively specify three digits, which are doubled.
#888, #1F3, #2AF, #902
- Can specify the three values in decimal with the rgb
notation. rgb(10,145,170), rgb(0,0,255) or
rgb(150,250,0)
- Can specify the three values using percentages.
rgb(4%,57%,67%), rgb(0%,0%,100%) or
rgb(59%,98%,0%)
- CSS
Fonts.
- Fonts have four basic paramaters: family, style, size and weight.
- Families have two flavors
- Actual fonts available on the system, such as Arial or
Helvetica. If the name contains spaces, you must
use quotes, like "Times New Roman"
- Generic fonts defined for all systems:
serif, sans-serif, cursive, fantasy and
monospace.
- Specify as a comma-separated list. Uses the first one available.
- Always end with a generic, since they are always available.
- font-family: Verdana, Arial, Helvetica, sans-serif;
- Styles are normal, italic or oblique
font-style: italic;
- Sizes
- Can be given as a dimension, usually points.
- Can be given as a percentage of the default size.
- Several absolute names,
small, medium, large, x-small, xx-small, x-large and xx-large.
- Relative sizes smaller and larger.
- The weight is the boldness of the font.
- Usually just bold or normal.
- Also takes percentages of the default.
- Can specify all at once, but usually separately.
- Text Properties
- text-decoration: underline, overline,
line-through.
- alignment: left, right, center and
justify.
- Several others to control spacing and indents.
[ Really Ugly Source ]
- Google Fonts
- HTML 5 allows fonts to be loaded dynamically by a web page.
- Google provides
a large collection of these for free.
- Google has
instructions
for using them.
- Header: <link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=family">
- You can request multiple families using & to
combine them.
- Use font or font-family to set the font in the
family.
- If a font name has spaces, use a + in the link
tag, and put the name in quotes within CSS.
- Using the font this way does mean your page will contact Google
whenever it loads.
- Google also permits you to download the font definition and
host it yourself, avoiding this repeated connection.
[ Google Fonts Source ]