Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Absolute Position

An element with position: absolute is taken out of normal flow: the other elements behave as if it weren't on the page at all, and they fill the space it left behind.

Its offsets work differently, too. They aren't measured from the element's original place, but from the edges of its nearest ancestor (its parent, the parent's parent, and so on) whose position is anything other than static. If there's no such ancestor, they're measured from the edges of the page (more precisely, of its first screen, as you'll see later in this lesson). For example:

.note {
	position: absolute;
	top: 0;
	right: 0;
}

If none of the ancestors of the element with the class note has a position other than static, this element sits in the top right corner of the page.

Square 2 has position: absolute, top: 0 and right: 0. It is in the top right corner of the page, and square 3 has moved into its place, next to square 1.

Instructions

  1. 1

    In the rule for #square2, change position from relative to absolute. The third square moves into the place of the red one, because for the other elements, the red square is no longer there. The offsets of the red square are now measured from the top left corner of the page, not from its original place, so it covers most of the first square.

  2. 2

    Move the red square to the top right corner of the page: delete the declaration left: 30px, change top to 0, and add right: 0.

Back

6/10

  1. 1. Normal Flow and Block Elements
  2. 2. Inline Elements
  3. 3. Inline-Block Elements
  4. 4. Hiding Elements
  5. 5. Relative Position
  6. 6. Absolute Position
  7. 7. Absolute Inside Relative
  8. 8. Fixed Position
  9. 9. Sticky Position
  10. 10. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.