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

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Igor Kałużny
Igor Kałużny
4,337 Points

#overlay Lightbox set to 100% is invisible.

When I set #overlay width and height to 100% (of body which has default of 100%) it is invisible. The overlay is visible only when height and width is set to px. My question concerns my project (not the one from the video) but everything has been set accordingly.

var $overlay = $('<div id="overlay"></div>');

$(".div").click(function(event){
  event.preventDefault();

  $overlay.show();
});

CSS

body {
  background-color: #f3f3f3;
}

#overlay {
  background: rgba(0,0,0,0.7);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  text-align: center;
}

2 Answers

Jonathan Dewitt
Jonathan Dewitt
8,101 Points

Instead of width and height 100% try instead setting right and bottom to 0

Igor Kałużny
Igor Kałużny
4,337 Points

Thx for your response. Now the width is 100%, but the height is only 100% of the window size. When i scroll down there's no overlay.

Igor Kałużny
Igor Kałużny
4,337 Points

I fixed it setting position to FIXED instead of ABSOLUTE.