troubleshooting Question

Use JavaScript/CSS to Dynamically Center a Popup DIV

Avatar of cnxmax
cnxmax asked on
Web Languages and StandardsJavaScriptCSS
3 Comments1 Solution6914 ViewsLast Modified:
I need some simple CSS/Javascript that will pop up a div on the center of the screen. The problem I'm having is that I can't make it happen 1) above everything else without messing up the document flow 2) be positioned right on the screen regardless of how far down the screen is scrolled.

Basically have this:

    left: 200px;
    top: 200px;
    width: 500px;
    height: 350px;
    background-color: #FF0000;
    position: absolute;
<div id="popimg">
    Here's the Div

So, what this is lacking is dynamic horizontal and vertical position, and keep in mind that I need it to work if the user is at the top of the page, or if they are scrolled half way down a long page. I'm assuming that with JavaScript somehow I can dynamically set the top and left for popimg.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros