Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7553657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:07:12+00:00 2026-05-30T11:07:12+00:00

There has to be a easy solution to this. I have been trying to

  • 0

There has to be a easy solution to this. I have been trying to work with jQuery to accomplish the effect i am looking for but, it just isn’t quite working… Also i suspect there is a CSS solution to the problem.

I have a div called “popup” with the following CSS:

#popup {
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;}

It covers the screen like a overlay… Inside this div i have another called #pnlEditOverlay that is a box that has a notification message or a edit form or something similar.

pnlEditOverlay is what i am trying to center vertically on the page

I use jQuery to expand the height of #popup to the document height, so that it covers everything:

$("#popup").css('height', $(document).height());

My issue is that i would like to vertically center #pnlEditOverlay on the page even if the page is large enough where it can be scrolled.

I have been using jQuery to reposition this div:

var offset = $("#pnlEditOverlay").offset();

        var topPadding = 75;
        $(window).scroll(function () {
            if ($(window).scrollTop() > offset.top) {
                $("#pnlEditOverlay").stop().animate({
                    marginTop: $(window).scrollTop() - offset.top + topPadding
                });
            } else {
                $("#pnlEditOverlay").stop().animate({
                    marginTop: 75
                });
            };
        }).scroll();

However this is not exactly what i want. It only repositions when the page is scrolled… So when the user is already scrolled halfway down the page, the div is hidden until they scroll…

In any case. I was wondering if there is a elegant CSS solutions to this. I simple want to put a box dead center on the page, even if the page is scrolled. I’m OK with using jQuery to set the styles of the div, however i would like to avoid implement a click event as there are MANY MANY buttons that could cause the div to be shown.

So the questions is, is there a CSS style or a small piece of jQuery that will center a div vertically and keep it there even if the page is scrolled?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:07:13+00:00Added an answer on May 30, 2026 at 11:07 am

    There is indeed a simple CSS solution for this. Firstly, use this for popup:

    #popup
    {
    position:fixed;
    height:100%;
    width:100%;
    }
    

    and this for your overlay:

    #overlay
    {
    position:fixed;
    top:50%;
    left:50%;
    margin-top:-y;
    margin-left:-x;
    }
    

    where x and y are half the width and height of your overlay div respectively. So you’d need to know the height and width of this div.

    This will take care of all your problems, even when the page will be scrolled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While it seems that this has been asked many times before, but there's a
There has to be a way to do this, I was googling information but
There has to be a simple explanation for this. I have a parent <div>
There has got to be an answer to this, but I am a total
I have been looking for a solution and I found many different opinions to
I'm not very good at SQL, so I've been trying to just handle this
I know I know this has been posted millions of times but I still
This question has been asked before - but with no satisfying answer at all!
I have been trying different techniques while designing this application, which to me is
I have been looking for some examples and solutions using the jquery-datatables-editable plugin and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.