Wednesday, February 04, 2009
CSS is a document styling language that has its own unique syntax. Compared to other programming languages, it's simple and easy to learn. A CSS rule is in the heart of CSS syntax.
HTML elements are styled using CSS rules made by assigning values to properties. A property describes an aspect of an element's presentation and is always followed by a value and is terminated by a semicolon. These declarations are always wrapped in curly braces which in turn is called a declaration block. Each declaration block has a selector. A selector is an element that is going to be rendered using the rules given within the curly braces.
Basic structures of HTML such as div, p, h1, h2, img are called elements. These elements can have different aspects. A p paragraph element can have font that is bold and in blue color. A generic p element will have regular font weight and black color. Through CSS we can style the p element such that it will render in bold blue color.
font-weight, and color are properties, bold and blue are the values. Notice that in CSS syntax there's a colon between a property and a value. Both font-weight and color are aspects of the presentation of the element p.
The rule selects all p elements which means all the paragraphs in the document will be styled with this rule.