======================================================= Cascading Style Sheets - Basic ======================================================= -Ian! D. Allen - idallen@idallen.ca - www.idallen.com Rule: Keep the *presentation* of your page separate from the *content* of the page. Use HTML tags to mark up the contents. Use styles/CSS to mark up the presentation, and keep the style in a separate file. Glossary * see http://www.w3.org/TR/CSS2/conform.html - define: element, attribute, descendant/ancestor, child/parent - define: property, style sheet Elements in a web page may be seen as a "Document Tree" -
and are the only children of - is the parent of and - every tag inside and has as an ancestor - every tag inside and is also a descendant of CSS syntax - when used as a tag attribute:- when used elsewhere (see http://www.w3schools.com/css/css_syntax.asp): selector { property: value ; property: value ; [...etc...] } - for example: p { color: red; margin: 0; } Basic CSS Selectors - see http://www.w3.org/TR/CSS2/selector.html * : any single element (not multiple elements!) ("* *" selects elements at least two-deep in the document tree) E : the element E, where E is any single HTML tag (e.g. h1, div, ul, p, etc.) E F : the element F located anywhere, at any level, inside element E (F is a descendant of E; E is any ancestor of F) E > F : the element F located directly inside element E (nothing in between) (F is a child of E; E is the parent of F) E.foo : every element E that has attribute class="foo" (multiple) (use *.foo or just .foo to apply to any element with that class) E#bar : the single element E that has attribute id="bar" (only one match) (use *#bar or just #bar to apply to any element with that id) E,F,G : (grouping) elements E and F and G all have these same properties Three Methods of specifying CSS - see http://www.html.net/tutorials/css/lesson2.asp - the method closest to the tag has priority Method 1: Style applied to an individual tag:
Method 2: Style moved to the
section: Method 3: Style moved to a separate CSS file: Two types of elements: Block and Inline * Block elements start a new line before and after and take the full width of the element that contains them, e.g. p, h1, ul, div - block elements can contain other block or inline elements - if you "float" a block element, you usually need to restrict its width or else nothing else will fit beside it * Inline elements run together on the same line and wrap at white space, e.g. i, b, em, strong, img, span - inline elements can contain *only* other inline elements, never block - top and bottom paddings and margins are ignored for inline elements; only the side padding and margins work Use