Absolute Position
With relative position, we could offset an element and other elements would still be positioned as if the offset wasn't there.
With absolute position (position: absolute;
), other elements will ignore the element completely. To understand this, let's look at an example. We set the offset in the same way as with relative position (left - left
, right - right
, top - top
, bottom - bottom
), with one difference: absolutely positioned elements aren't offset from their static position, but from the first parent element that has a position other than static.
If no parent element has a position other than static, it will be offset from the page. For example:
.element {
position: absolute;
left: 200px;
top: 100px;
}
If an element with the class element
only has parent elements with a static position, it will be offset 200px from the left of the page and 100px from the top of the page.
Instructions
Change the element with id square2 (#square2
) position to absolute and set the top offset to 200 pixels and the left offset to 0 pixels.
Notice that the third element now ignores the second element and has moved to its position.
Start programming for free
7/10