Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

absolute positioning + relative positioning

The video mentioned that absolute positioning allows a child element to be positioned relative to the parent element. Is that only when the parent element uses relative positioning? or can absolute positioning be used whenever on a child element (regardless if relative positioning is applied to the parent element)?

1 Answer

Hi Julia, The positioning of the absolutely positioned child will be relative to the first parent going up the nested tags that has either absolute or relative positioning. Meaning that the tags that have the default static do not affect the positioning styles (top, right, bottom, left).

This way you can set, say a section to be relatively positioned. Then, have a tag – maybe a button or some other element – nested multiple tags down the stack be absolutely positioned using the section. This is provided that there are no other parent between your element and the section also styled as position absolute or relative. ;-)