adv banner
HTML and CSS  Home HTML and CSS Tutorials CSS Syntax
rss

CSS Syntax

Author: Mark Pearson More by this author
Browse Pages: << <  1  2  3  4 > >>


Basic Syntax: Contextual Selectors

Contextual selectors are merely strings of two or more simple selectors separated by white space. These selectors can be assigned normal properties and, due to the rules of cascading order, they will take precedence over simple selectors. For example, the contextual selector in

P EM { background: yellow }

is P EM . This rule says that emphasized text within a paragraph should have a yellow background; emphasized text in a heading would be unaffected.

Properties
A property is assigned to a selector in order to manipulate its style. Examples of properties include color , margin , and font .

Values
The declaration value is an assignment that a property receives. For example, the property color could receive the value red .

Grouping
In order to decrease repetitious statements within style sheets, grouping of selectors and declarations is allowed. For example, all of the headings in a document could be given identical declarations through a grouping:

H1, H2, H3, H4, H5, H6 { color: red; font-family: sans-serif }

Inheritance
Virtually all selectors which are nested within selectors will inherit the property values assigned to the outer selector unless otherwise modified. For example, a color defined for the BODY will also be applied to text in a paragraph.

There are some cases where the inner selector does not inherit the surrounding selector's values, but these should stand out logically. For example, the margin-top property is not inherited; intuitively, a paragraph would not have the same top margin as the document body.

Comments
Comments are denoted within style sheets with the same conventions that are used in C programming. A sample CSS1 comment would be in the format:

/* COMMENTS CANNOT BE NESTED */


print this page tell a friend subscribe to newsletter subscribe to rss
Rate this Material: Bad 1 2 3 4 5 Excellent
Browse Pages: << <  1  2  3  4 > >>

Add comments to "CSS Syntax"