Web designers gained a great deal from the CSS2 specification, especially when it comes to increased flexibility to position HTML elements exactly where they want them within Web pages. Keep reading to learn more.
Introduction to CSS Positioning Properties Part 1 - The "position" property (Page 5 of 6 )
As its name implies, this property is used to set the type of position applicable to the selected element. The following values can be defined:
position: static; (default behavior for all elements)
position: relative; (uses relative positioning for this element using the top, right, bottom and left properties)
position: absolute; (uses absolute positioning for this element using the top, right, bottom and left properties)
position:fixed; (uses fixed positioning for this element using the top, right, bottom and left properties)
As previously mentioned, for most of positioning schemas, itís necessary to specify "top," "left," "right" and "bottom" properties. Letís see each one of them in detail.
The "top," "right," "bottom"and "left"properties
As we can see, to properly implement CCS2 positioning schemas, we need to define "top," "left," "right" and "bottom" properties. However, specifing both "top" and "bottom," or "left" and "right" properties simultaneously, will render an undesirable visual effect, and not achieve what we really want from them. Generally, weíll end up utilizing the top and left properties to efficiently position an element in the desired location.
We can use the following values for these properties:
Fixed Length: Itís possible to specify a fixed value expressed in pixels (px), points(pt), inches(in), centimeters (cm), millimeters (mm), ems (em), or picas (pc). For instance, we can define several examples, such as this:
However, the last example is somewhat unusual, and would not normally be used. For most cases, specifying the left and top properties is the safest way to position an element in a Web document.
Also, percentage values may be set. Itís possible to assign a percentage value, generally well suited for liquid designs, where the elementís size gets expanded or collapsed according to different screen resolutions:
Or, using the right and bottom properties:
In our two last examples, we specified a percentage value for each element. In the first case, the content selector will be positioned at 30 percent of the parent elementís width and 20 percent of its height. The second case shows that the element will be positioned at 20 percent of the parentís width and 30 percent of its height. Once again, this approach is rarely used. Keep in mind that "top" and "left" properties are perfectly suitable for all of the situations.
Thatís our quick guide to CSS2 position schemes in Web documents. Certainly, concerning each CSS property, browser support may vary considerably, particularly when referring to old browsers.
Itís time to have a look to another CSS2 visual property: the "display" property.