CSS3 <div> for use in Positioning from Links

The first attempt shall be from w3schools for Positioning.

The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute or sticky).

This div element has position: static;

An element with position: relative; is positioned relative to its normal position.

Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.

This div element has position: relative;

Note that the two blocks above seem to extend past the right edge of the page. I know this because the bottom line is right aligned.


An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.

A fixed element does not leave a gap in the page where it would normally have been located.

Notice the fixed element in the lower-right corner of the page. Here is the CSS that is used:

Omitting px in the style definition for bottom or right used some strang(?) measurement. When I added px the result was as expected.

This div element has position: fixed;

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).

However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

Note: A "positioned" element is one whose position is anything except static.

It appears that proper positioning requires measurement expressed as px or something else. It cannot just be a number.

This div element has position: relative2;
This <div> element has position: absolute2;

An element with position: sticky; is positioned based on the user's scroll position.

A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).

I shall omit the exercise for sticky because it uses -webkit-sticky in the style definition; I have not yet learned anything about webkit.

These exercises are not related to the Castro book I am learning from.