statementsBy now we should know how a style sheet works, and we should have a bit of an idea of what it should look like. Now it's time to start looking at the nuts and bolts of the technology. Before, in How do style sheets work? we saw that a style sheet is a series of statements. There are several types of statement. We'll take a quick look at each of these, but the really important one for us is Rules, which we leave for last. If you're new to style sheets, you'll probably do well by skipping straight down to the section on rules, and leave the other types of statement for use as a reference once you have a deeper knowledge of style sheets. @rulesYou can think of an @importIn CSS1 the only valid The @import url(http://www.westciv.com/styles/style1); alternatively, you can use also use the form @import "http://www.westciv.com/styles/style1"; The url can be either a local file (in that case you use a relative url) or an absolute url, as in this case. CSS2 introduced the concept of media, and allows conditional importing of style sheets based on the media that a page is being displayed in. For more on this media conditional importing, see the section on media. Browser supportDetailed browser support information for this feature can be found in the full version of the Westciv CSS Guide, or in our CSS Browser Support Table. @media
@media print { We'll learn more about Browser supportSee the full Westciv CSS Guide, or our CSS Browser Support Table.
@page { We will cover Browser supportSee the full Westciv CSS Guide, or our CSS Browser Support Table. CommentsBecause human beings have to develop, edit and share style sheets, they can be commented. A comment has the form /* This is a style sheet comment */ Comments can be multilined. Browser supportSee the full Westciv CSS Guide, or our CSS Browser Support Table. HTML comment tagsBecause older browsers don't support cascading style sheets, to ensure that these browsers don't display a style sheet embedded in them as text, style sheets can be surrounded by HTML comment tags ( Browser supportSee the full Westciv CSS Guide, or our CSS Browser Support Table. RulesRules or Rule Sets are what we are primarily concerned with, at least to begin with. A rule is a statement that tells a browser how to draw a particular element on a web page. As we saw a little earlier, a rule has two parts, a Selector and a Declaration. We are going to look in detail at each of these, as understanding both is essential to working with style sheets. A selector identifies, or selects the elements on a web page that are affected by the rule. The declaration then tells a browser how to draw any element on a page that is selected by the selector. Sounds a little complicated? It's a tricky idea, because it is probably quite different to your experience with style sheets in say a word processor. Let's take a look at an example or two. One of the most common elements on a web page is a paragraph. If you are versed in HTML, this is the Suppose we want all of the text in paragraphs to be in the font you are (hopefully) seeing now, Verdana. In a style sheet, we want to create a rule which selects paragraphs, or to put it another way, we want to create a paragraph selector. Sounds complicated? Well, below is the paragraph selector p Any guesses for the selector to select the < In addition to selectors for HTML elements (HTML Element Selectors) there are many other important types of selector, which we will be covering in the next section. Now, our plan was to create a rule that tells a browser to draw paragraphs in a certain font. We've created the selector, but now we need to create a declaration that tells the browser how to draw the selected elements. Declarations are inside curly braces - {font-family: Verdana} And if we were to get really ambitious, and want the text to be red, we would have a declaration like the following {font-family: verdana; color: red} Note that we have separated the properties in the declaration by a semicolon. Putting the selector and the declaration together, we get the complete rule. p {font-family: verdana; color: red} We've gone into quite a bit of detail about rules. That's because they will generally be the largest part of your CSS coding. Rules are the only type of statement you need to know about to do the vast majority of what most people want to do with style sheets. You'll see that the bulk of this guide is concerned with the major aspects of rules: selectors and properties. next: selectors(C)1997-2001 Western Civilisation Pty. Ltd. |