8. Laying out a page with CSS PositioningSo far, we've been looking at the typographical aspects of style sheets, more or less. Now its time to take a look at the page layout side of CSS. WhitespaceWell designed publications look professional for a number of reasons. One of them is the use of whitespace (or neutral space). This breaks up the information on a page for legibility. Good use of neutral space (typically margins, the space between paragraphs and headings, as well as the use of indenting) makes information more readable. It draws the user's eye toward the most significant information (headings), and to logically related "chunks". In this lesson we are going to develop rules that apply these layout aspects to our page. MarginsTypically, the text on a page is framed by a margin. On web pages, until now, we either made use of tables to create a margin (very very bad), or put up with the default margins as built into the browser. You can specify the Exercise 1First, let's create a margin around our whole page. To do this, we'll select the body, and apply a margin property to it.
let's make it a sizable amount, say 10%, as we'll create a nice effect in a minute, and we'll need a bit of margin to achieve it. Test your handy work. Save the style sheet then open the page in a browser. Indenting and OutdentingHeadingsIts a common typographical effect to draw attention to headings by the use of outdenting, so that they hang outside the main body of text. That's what we'll do now. There are a number of ways you could go about doing this. One would be to create a negative left margin ( Exercise 2Using either of the techniques I outlined above, create rules for several levels of heading that give outdenting to the headings on a page. You'll need a simple selector to select headings of level 1, level 2 and so on, and then a property to create the indent, using either a negative Answers at the bottom, as usual. TextIn a well designed publication, the first line of a paragraph may be indented, while subsequent lines in the paragraph are flush left with the margin. This emphasizes the beginning of a logical chunk of information. Exercise 3To reinforce the last exercise, let's have each of our paragraphs begin with indented text. We'll use a positive, rather than negative text-indent value this time. You should be getting the hang of this now, so we need a rule that selects paragraphs (the P element) then applies a text-indent of 10, 20 or more percent, to taste. Answers at the bottom of the lesson. NextThere are many more page layout features to style sheets, which you can learn about from one of the more in-depth tutorials mentioned in the resources section. In this lesson we've learnt about the rudiments of working with neutral space on web pages. Next we are going to take a look at a powerful, though a little tricky aspect of style sheets that effectively lets you create your own HTML elements (well, something that has a similar effect). Example Answer for Exercise 1
Example Answer for Exercise 2
Example Answer for Exercise 3
(C)1997-2001 Western Civilisation Pty. Ltd.
|