CSS Syntax
In a nutshell, CSS is a collection of 3 kinds of rules, and each rule has 2 parts to the syntax.
The 3 Kinds of Rules
Instead, you can apply CSS styling in the form of 3 kinds of rules.
- HTML Selector: you can change the default html properties with your choices
- code example:
- h1 {font-size: 1.4em:}
- h2, h3 {font-size: 1.2em:}
- p {font-size: 12pt:}
- CLASS: classes can be reused but are specified
- code examples
- .myclass {font: bold 14px Verdana;}
- ID: these can only be applied ONCE on a page, so they are used largely for positioning
- code example
- #header { background-color: #ffffff; height: 140px; margin: 0;}
- note: next sections divs
- #header { background-color: #ffffff; height: 140px; margin: 0;}
- code example
The 2 Parts of a Rule
There are basically two parts to a rule (selector and declaration)
- selector: (remember the 3 kinds: HTML(h1), class(.myclass), or ID(#container))
- declaration block: property and value (always in a pairs called declarations, separated with a colon)
selector { property: value; property: value; }
Where does the CSS go?
CSS styles
- Best place: Externally linked stylesheet
- you add CSS syntax to your HTML file once, and then all edits are done directly in your CSS file
- small changes in one file affects all linked pages
- styles are written and stored in an external .css file
- example www.melaniestewart.com/css/twoColFixLtHdr.css
- you provide a link in the html head section to the css file
- except for Spry Navigation this entire site's layout and styles are in the external css file <stylesheet link href="css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
- you add CSS syntax to your HTML file once, and then all edits are done directly in your CSS file
- JUST OK place: Internally linked style sheets
- between style tags in the head of each and every document
- that's why it is only an OK choice, you can't make global changes easily
- between style tags in the head of each and every document
- Worst place: Inline styles
- Use sparingly because your ability to globally make mass changes is greatly diminished.
HTML
- you style your web pages in CSS as above
- you provide a link in the html head section to the css file
- except for Spry Navigation this entire site's layout and styles are in the external <stylesheet link href="css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
- you provide a link in the html head section to the css file