= Basic CSS Reference = This is a quick 'cheat sheet' for CSS (Cascading Style Sheets). == Selectors == * **selector**: The selector defines which piece of the document will be selected (e.g. to select all ''
'' tags with a class of ''foobar'', you'd use ''p.foobar {}'')
* **declaration**: a combination of properties and values that declare something about a selector (e.g. ''p.foobar { color: red; }'' ). The 'declaration block' is the set of all declarations for a given selector.
* Basic selectors allow you to select all elements with a certain HTML tag (e.g. to get all '''' tags: ''em {}''), all elements with a specific class (e.g. ''.myClass {}''), or a single element tagged with an ''id'' attribute (e.g. ''#myElement {}''). Of course, you can mix and match; ''em.myClass {}'' would only get '''' elements with ''myClass'' (e.g. '''')
* You can apply multiple class selectors in a single element selector. For example, ''.hello.there {}'' would match ONLY elements with ''class='there hello' '' (in any order). This also means that period isn't valid in a classname.
* You can also create **attribute selectors**, e.g ''p[class]'' would select all '' '' elements with a class attribute. This can be useful for selecting various types of input elements, e.g. ''input[type="radio"] {}'' or ''input[type="checkbox"] {}''
* You can create **descendant selectors**, these basically ask for a child element that is a descendant of another, e.g. ''h1 em {}'' would get all elements where an '''' tag is inside an '''' tag. The '''' tag can be any number of levels down; if you want to select an '''' //only// if it is the //immediate// child of an ''
'' tag, you'd use ''h1 > em {}''.
* There are **pseudo classes** you can use to select things based on actions that have been taken in the document. ''a:visited {}'' is one good example; it lets you select all visited links. You can also combine these with normal classes, e.g. ''a.foo:visited {}''. Other pseudo classes include ''hover'', ''active'' and ''link''.
== Sizing ==
* CSS has many methods for sizing objects. ''em'' is the height of the current font (as defined by font-size), ''ex'' is the height of a lowercase x (although generally is just 1/2 the font size), ''px'' is pixels. There are also absolute measurements, such as ''in'', ''cm'', ''mm'', ''pt'' (72/inch), etc.
* It's generally best to use relative measurements... pixels when those are necessary (they scale to a 96dpi 'reference pixel' for printing) and ems for other measurements, esp. those that should grow or shrink. Percentages are also good, but fixed measurements such as points, centimeters or inches are not.
* That's because monitors are all set to different dpi settings, and so using an absolute measurement will change the number of pixels in a given measurement. For example, if you say ''margin: 1in'' and the monitor is set to 120dpi, then you'll get a 120 pixel margin. But if your monitor is set to 96dpi, then you'll get a 96 pixel margin.
== Text ==
* The ''font-size'' declaration lets you control the size of fonts. It is generally best to do these in either pixels or percentages (e.g. ''font-size: 12px;''). Don't forget that percentages inherit, though (e.g. 80% * 80% = 64%).
* ''font-weight'' lets you control the boldness of a font. You can do this with numbers (100 to 900 in 100 increment values), but nobody does. Instead, use ''normal'' and ''bold'' or //maybe// ''bolder'' and ''lighter''. For example: ''font-weight: bold;''
* ''font-style'' can be either ''italic'' or ''oblique'' (or normal), but ''italic'' is what you want. Your browser will pull an oblique face if it can't find an italic face, but not the other way around. ''font-variant'' can be used to do cool things, like small-caps. ''text-transform'' lets you force text to all caps, to lowercase, etc. ''text-decoration'' handles junk like strikethrough; the most common use of ''text-decoration'' is ''text-decoration: none'' on an '''' element, which removes the underline from a hyperlink.
* There is an overall ''font'' declaration that lets you specify multiple properties at once. It can also take a few specific keywords: ''caption'', ''icon'', ''menu'', ''message-box'', ''small-caption'', ''status-bar''. These actually represent an entire set of font properties (''font-family'', ''font-style'', ''color'', ''font-weight'', etc.) which make the font look like the system font in question. This can be useful if you're building web-apps or the like.
* ''text-indent'' lets you both indent and outdent of the first line of text.
* Horizontal and vertical alignment can be done with the ''text-align'', ''line-height'' and ''vertical-align'' declarations. Note that line-height only specifies //minimum// values
* ''letter-spacing'' and ''word-spacing'' adjust their namesakes. They can be handy from time to time.
* ''white-space'' can be used to adjust the fact that browsers normally collapse multiple spaces into one. You can use 'pre' which is like HTML's
tag, or 'nowrap', which doesn't wrap things. And there are a few others.
== Opacity ==
* You can set the transparency of an element with the opacity property
== Block Elements & The Box Model ==
* CSS layouts are fundamentally based on the **CSS Box Model**, which lets you create 'boxes' (of text, empty space, graphics, etc.) on the page, and then control how they are positioned and sized. Pretty much every element on a page is affected by the box model.
* Any given box has a content area, padding (space inside the border), a border, and then margins (space outside the border). **Width and height generally go from the inner edge** of the box, not the outer edge. So if you make a box with ''width: 100px; padding: 10px;'', the total width of the box on the page will be 120px (100px width + 10px left side padding + 10px right side padding).
* Any given element in an HTML document can be either 'block level' or 'inline'. Block elements are generally used for layouts, and have a linebreak both before and after the element unless otherwise specified. Inline elements are...well... inline in the content, and do not have said linebreak.
* ''display'' changes elements to block or inline. Therefore, if you wanted to change a ''