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

centering a lightbox with jquery

Hi all, I have a lightbox that I want to appear in the center of the screen upon click. Centered horizonally and vertically once clicked on the buy button.

having trouble!

http://jsfiddle.net/d6DH6/

2 Answers

Try using this technique found at: http://css-tricks.com/centering-in-the-unknown/ I updated your jsfiddle here: http://jsfiddle.net/d6DH6/7/

All I did was remove .buy-links-pop-up from the unordered list and wrap it in another div with .block. Then make the block display:none; and changed the jquery to show and hide .block when the link is pressed. The css block:before and .buy-links-pop-up will then take care of centering and vertically aligning .buy-links-pop-up to the middle of the page. You want to make sure that html, body, and .block have a height of 100% so that it goes to the middle of the window vertically. Also make sure that block has a width of 100%.

how to center an image inside the lightbox