|
Cascading Style Sheets Cascading Style Sheets act as a "template" that can control the layout and design of your pages. They work separate from HTML, giving you easier maintainability. They can define everything from your link and text colors to page margins, backgrounds colors, font weights and sizes etc. Here is how they work: Rules, Selectors and Declarations: H1 { color: blue } The example above is a simple CSS rule. A rule consists of two main parts: selector ('H1') and declaration ('color: blue'). The declaration has two parts: property ('color') and value ('blue'). The selector is the link between the HTML document and the style sheet, and all HTML element types are possible selectors. Placing a 'STYLE' element inside the 'HEAD' element. Style information can be stored in an external file and referenced by any number of Web pages. This is useful if you are developing an entire website and would like your style to remain consistent over many individual webpages. Since we focus on designing a single webpage, we will instead place our "STYLE" element within the "Head" element of our document. This allows you to change the appearance of a single Web page. The <STYLE> element has one paremeter, TYPE, which specifies the internet media type as "text/css." The <STYLE> tag is followed by any number of STYLE definitions and terminted with the </STYLE> tag. Older browsers will ignore the <STYLE> element, and will treat the tag as part of the document body and render it as such. To avoid this, we will "hide" our style definitions as "comments" <!-- style definitions here -->. The following example, embedded within the <HEAD> element of a webpage will yield a page with a black background and white text in the Garamond font face. <STYLE TYPE = "text/css"> Style Sheets with Colors and Fonts: Color can be defined within the style definition as either a keyword or a hexidecial color value. There are 16 color keywords that can be used: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. There are four common font properties that are commonly defined in a style sheet:
Style Sheet Examples Here is a rule that will set general defaults, e.g. text and background colors, and fonts: <STYLE TYPE = "text/css"> Note that I have defined three font families.
Remember that for a font to display it must be installed on the user's
system. To work around this, you can specify a single type, or alternative
font families. Here is
an example of a rule defining the font family, style, weight and size
for the <H1> element: For More Information See These CSS LINKS:
|