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
Arikaturika Tumojenko
8,897 PointsNo offsets for the relative positioning?
For the absolute positioning we've used offsets. Aren't they necessary for relative positioning also?
4 Answers
Erik Nuber
20,629 PointsShould mention that an absolute positioned element that has no relative parent will scroll with the window because it defers to the body.
If you want that element to stay in a specific spot that is when you would use fixed.
Erik Nuber
20,629 PointsBoth absolute and relative elements are positioned with Top, Left, Right and Bottom. The difference is an absolute positioned item is positioned based on the closest parent that has position relative. If there isn't a relative positioned item it then defers to the body of the document.
A relative positioned element is positioned relative to its normal position.
<div id="relativePositionedItem>
<div id="absolutePositionedItem>
</div>
</div>
relativePositionedItem {
top: 20px;
left: 20px;
}
absolutePositionedItem {
top: 20px;
left: 20px;
}
Here the div that is relatively positioned will be 20px from both the top and to the left of where it was originally positioned. The absolute positioned div would be 20px from the top and left of the relatively positioned div.
Arikaturika Tumojenko
8,897 PointsSo by positioning an element relative it actually changes nothing, unless we specify some offsets?
Erik Nuber
20,629 PointsCorrect. It can be used simply to position an element absolute. I saw your other question regarding img and caption this is why that was done.
Arikaturika Tumojenko
8,897 PointsArikaturika Tumojenko
8,897 PointsYes, exactly, my question related to the image and the caption was on the same topic. Now it makes sense. Thank you for the explanation :).