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 trialAmber Lim
4,707 PointsWhy do I need to set absolute positioning for full-screen overlay?
The overlay appeared when I include absolute positioning. Is there a reason why it didn't appear without absolute positioning, even though the width and height are set to 100%. Shouldn't the overlay div show when its width & height is 100%?
Correct my logic if I'm wrong, which apparently I am. Thank you.
Here's what worked:
#overlay {
background-color: rgba(0,0,0, .7);
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
};
Here's what didn't:
#overlay {
background-color: rgba(0,0,0, .7);
height: 100%;
width: 100%;
};
2 Answers
Tim Acker
Front End Web Development Techdegree Graduate 31,247 PointsBecause without absolute positioning, even if you set the height and width to 100%, the element's default behavior is to appear in the normal flow of the document. So by setting its position to absolute and giving it a starting point of top 0 and left 0, you are removing the element from the normal flow and setting its precise location.
nfs
35,526 PointsThanks
Amber Lim
4,707 PointsAmber Lim
4,707 PointsThanks x100 Timothy. Makes full sense now. My logic never fails to fail me.