Cascading Style Sheets (CSS) are used to style html documents. A CSS statement has two parts: a selector, which specifies the part of the document, and declarations, which describes the formatting to apply. A typical piece of CSS looks like this:
The key to CSS is understanding how selectors work. The table summarises the main selectors in CSS 2.1.
||Matches all the
||Matches all elements with the
||Matches the single element with the id
||Matches all elements
||Matches all elements.|
||Style information not available in the document tree.
An ID can only be used once within a document, whereas a class can be used multiple times. In the style sheet the ID selector has greater weight than class selector. ID's are generally used to identify the top level containers on the page, classes are then used to identify the lower level containers. ASP.NET has a problem with ID's, it tends to mangle the id attribute for elements with
runat="server". For these elements you have to stick with the class attribute, which ASP.NET leaves alone.
Selectors can be grouped as a comma-separated list, if they share the same declaration block. For example:
With grouped decent selectors, you need to be careful that you repeat the whole decent. For example
#sidebar h2, h3 will select the
h2 elements in the sidebar, plus the
h3 elements in the whole document.
I'm embarrassed to admit that I learnt my basic CSS from Sams Teach Yourself CSS in 10 Minutes by Russ Weakly. But hey, honesty is the best course, and its actually an OK book.