5.5: Absolute
An absolute: element is
is isolated from the normal flow and other elements
BUT will respond to other positional properties and values.
Copy and paste the following.
Explore more
Notice the placement as you:
Add top and left values set to 0px.
What does this do and why?
Change top and left to 100px, to 50%, 5em.
Choose different values for top and left.
Set squareBlue back to 0px for both top and left.
Add a another square (squareRed) with width and height set to 150px. 1. Where was it placed? What happens when you swap the squareBlue and squareRed classes in the HTML?
Play around with top and left values of squareRed.
Where you set the position property of an element is important both in html and css
Challenges
Gold':'
Center the blue square on the document
Blue':'
Center the red square inside the blue square
Challenge Answer
Set squareBlue top(x) & left(y) to 50%. If squareRed top & left values are set to 50% as well, what do expect? inside squareBlue. The left top corner is the anchor point for the element and therefore the point at which the element will be placed on the document (or in relation to its ancestor)
Add a margin-top & a margin-left with a negative value which is 1/2 the square's width and 1/2 the square's height to both squares. This should center the square.
Last updated