|
Instructional Module X22c
|
|
||
| |
|---|
|
Cascading Style Sheets Level 2 (CSS-2) offers a wide variety of layout control possibilities that weren't there in HTML. Laying out pages using CSS offers a number of advantages over doing the same layout with tables:
As always, there are disadvantages:
In this module we'll take a swift look at the 2-dimensional aspects of positioning. We'll go over 3-D positioning floating in module X23c "Layers in CSS". There's lots of detail missing from this though - it's only intended as an introduction! |
| |
|||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
CSS provides four ways to line things up:
We'll take a look at each in this section... |
|||||||||||||||||||
|
Static Positioning
|
Here's a "freebee": Static positioning is what you get if you don't do anything else. In other words, Static positioning follows the normal flow of elements from top to bottom, as written in the code. |
||||||||||||||||||
|
Fixed Positioning
|
With fixed positioning, you can determine an element's position relative to the window it appears in. In other words, if a page has more text than what fits in one window, you can cause some of the elements to scroll and other elements to remain in place. This is rather like frames, except that the elements you fix in place can be anywhere in the window, including smack in the middle! That's not usually a helpful thing to do, but there are many useful ways you can use this.
|
||||||||||||||||||
|
Reality Check
|
What is the earliest version of each major browser that supported fixed positioning? Suggestion: Check Index DOT CSS, http://www.blooberry.com/indexdot/css/supportkey/classify.htm |
||||||||||||||||||
|
Absolute Positioning
|
Absolute positioning refers to where an element appears with respect to its parent element. This differs from fixed positioning, which refers to the window. To make things interesting, CSS allows us to specify absolute positioning in either absolute measures or relative values.
Absolute positioning only works as advertized if the parent element has specific height and/or width set. If the parent's size depends on its content, absolute positioning is ignored.
|
||||||||||||||||||
|
Reality Check
|
What browser versions support absolute positioning? |
||||||||||||||||||
|
Relative Positioning
|
When we specify relative positioning, what is it relative to? It's relative to the position the element would have occupied if we left it alone - that is, relative to its static position. Relative positioning causes an element to move a specified distance from its own normal position. This might results in overlapping other elements. Again, CSS makes life interesting: we can use either absolute measures or relative values to specify an element's relative position.
|
||||||||||||||||||
|
Reality Check
|
What browser versions support relative positioning? |
||||||||||||||||||
|
Side Offsets
|
When we specify positions, it is with measures from one of the sides:
Generally, two offsets are needed to make sure elements end up in the right place. Usually, it's the top and the left. |
||||||||||||||||||
| |
|
|---|---|
![]() |
Click here for review questions. |
|
Audience |
|
| Objectives | On successful completion of this module, you will be able to:
|
| Module X22c: Layout with CSS |
This document is part of a modular instruction
series in Computer Instruction. For more information, see the overview
or the list of modules in this series, X: XML, XHTML,
DHTML, CSS. This document has been used in the following classes: INP
270 .
|
| History: |
Original: 24 March 2003, by Laurence J. Krieg
Last modification: Monday, 31-Aug-2009 11:48:08 EDT |
| Copyright |
Copyright © 2003, Laurence
J. Krieg, Washtenaw Community College Instructors: You may point to this file in your Web-based materials; however, its location may change without notice. Students: You are welcome to make a copy for your personal use. All other uses: Please contact the author, Laurence J. Krieg, for permission: krieg@ieee.org. |