A brief CSS2 tutorial for HTML
A brief CSS2 tutorial for HTML
We begin with a small HTML document:
Bach's home page
Johann Sebastian Bach was a prolific composer.
To set the text color of the H1 elements to blue, you can write the following CSS rule:
H1 { color: blue }
A CSS rule consists of two main parts: selector ('H1') and declaration ('color: blue'). The declaration has two parts: property ('color') and value ('blue'). While the example above tries to influence only one of the properties needed for rendering an HTML document, it qualifies as a style sheet on its own. Combined with other style sheets (one fundamental feature of CSS is that style sheets are combined) it will determine the final presentation of the document.
The HTML 4.0 specification defines how style sheet rules may be specified for HTML documents: either within the HTML document, or via an external style sheet. To put the style sheet into the document, use the STYLE element:
Bach's home page
Johann Sebastian Bach was a prolific composer.
For maximum flexibility, we recommend that authors specify external style sheets; they may be changed without modifying the source HTML document, and they may be shared among several documents. To link to an external style sheet, you can use the LINK element:
Bach's home page
Johann Sebastian Bach was a prolific composer.
The LINK element specifies:
the type of link: to a "stylesheet".
the location of the style sheet via the "ref" attribute.
the type of style sheet being linked: "text/css".
To show the close relationship between a style sheet and the structured markup, we continue to use the STYLE element in this tutorial. Let's add more colors:
Bach's home page
Johann Sebastian Bach was a prolific composer.
The style sheet now contains two rules: the first one sets the color of the BODY element to 'red', while the second one sets the color of the H1 element to 'blue'. Since no color value has been specified for the P element, it will inherit the color from its parent element, namely BODY. The H1 element is also a child element of BODY but the second rule overrides the inherited value. In CSS there are often such conflicts between different values, and this specification describes how to resolve them.
CSS2 has more than 100 different properties, including 'color'. Let's look at some of the others:
Bach's home page
Johann Sebastian Bach was a prolific composer.
The first thing to notice is that several declarations are grouped within a block enclosed by curly braces ({...}), and separated by semicolons, though the last declaration may also be followed by a semicolon.
The first declaration on the BODY element sets the font family to "Gill Sans". If that font isn't available, the user agent (often referred to as a "browser") will use the 'sans-serif' font family which is one of five generic font families which all users agents know. Child elements of BODY will inherit the value of the 'font-family' property.
The second declaration sets the font size of the BODY element to 12 points. The "point" unit is commonly used in print-based typography to indicate font sizes and other length values. It's an example of an absolute unit which does not scale relative to the environment.
The third declaration uses a relative unit which scales with regard to its surroundings. The "em" unit refers to the font size of the element. In this case the result is that the margins around the BODY element are three times wider than the font size.
» لغة (HTML 5 وتصميم مواقع الويب
» دورة متقدمة في HTML
» الإيعازات attributes في لغة HTML
» المصطلحات الهامة في لغة HTML