CSS Notes

CSS Syntax

Ruleset:

Example:
p {
border: 2px solid purple;
}

The Selector in this example is "p" (or paragraphs)
The Decleration block is inside the curly braces - "border: 2px solid purple;"

In the Declaration block, are declaration rules

The propertyof the declaration block is a descriptive name
Each property has a declared value that is given to the property

the property of the above example is p
them value of the above example is 2px solid purple;

CSS syntax

CSS Selectors

Vocabulary Review

Selectors Review

CSS Boilerplate

type {
    property:  value;
}

.class {
    property:  value;
}

#id {
    property:  value;
}
                

Cascading and Specificity

"Cascading" refers to the way that style properies "cascade" down the DOM tree, starting at the top or parent. Any style applied to a parent type (body, h1, ul) will affect or cascade to all the child elements.

Example
ul { background-color: blue; font-weight: bold; }
li { background-color: orange; }

In the aboce example, the background for li elements will be different than the ul, but all the text in the li will be bold because there is no ruleset for font-weight.

Units

Units based on inches

Units based relative to the size of something else on the page

Percentages

Makes the "box" the percent/fraction of the size from the box it is inside

For a box inside the whole page, 50% is 1/2 the size of the page. If the target is inside another box, it'll be 1/2 the size of the parent box.

Percentages do NOT include the border or the padding.

CSS can also using percentages for scaling things up or down.

Separating Style

<link rel="stylesheet" href="URL/Filepath of .css">

For this document, the CSS is linked like this:
<link rel="stylesheet" href="../style.css">

This link element goes inside the head of the HTML document. This will take place of the style element.

Color

rgb lighting

Fonts

font-family = typeface (font as we may think of it in relation to word processors); like Times New Roman, Helvetica or IMPACT

If the browser or device doesn't understand the font chosen, it'll revert a default font-family

The "quotes" are recommeded for font families that have spaces in their names like "Times New Roman" compared to Helvetica.

Generic Font Families and Font Stacks

If you don't care what font is shown but know what style font you want, you may choose a generic font.
It is best practice to add a generic font at the end of the font font list.

Generic font-family:

Generic fonts are used more as a fallback if the browser doesn't have the declared font in the style.

Font Stacks

A list of font familys; usually ending with the generic.

Example: Windows has Constantia but it's only available on Windows. We can set the next font to take place to Georgia. If the browser doesn't have that font, we can utalize any serif font.

This is written as:
.class {font-family: Constantia, Georgia, serif;}

Font Properties

Shorthand font Property

Instead of typing out:
".class { font-style: italic; font-size: 24px; font-family: Times; }"
We can use the shorthand:
".class { font: italic 24px Times; }"

font shorthand

using the shorthand font, you have to write the font features in a specific order:

  1. font-style
  2. font-variant
  3. font-weight
  4. font-size (line-height)
  5. font-family

Written out: { font: font-style font-variant font-weight font-size font-family; }
Example: font: italic small-caps bold 24px Helvetica

Note: font-size and font-family values are required when using font.

HTML vs CSS

<em> vs italic

<strong> vs bold

The <em> and <strong> elements identify the meaning of the text.
This can be helpful for screen-readers, smart speakers, etc...

Italic and bold are aesthetics changing how text appears on the screen.