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

  • Home
  • SEARCH
  • 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 7732913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:51:01+00:00 2026-06-01T06:51:01+00:00

I am tying to create a custom alert box with fixed positioning. It works

  • 0

I am tying to create a custom alert box with fixed positioning. It works great in chrome, but I can’t get the dynamic position right in Firefox.

I set a modal container to equal the size of the document

$('#modalContainer').height($.getDocHeight());

and then the #alertBox div lives within modalContainer and has position:fixed style.

I am using the jquery offset function to set the top and left values for #alertBox like so:

var off_top=$(window).height()/3-$('#alertBox').height()/3;
var off_top=100;
var off_left=$(window).width()/2- $('#alertBox').width()/2;
$('#alertBox').offset({top:off_top,left:off_left});

In chrome the top value gets set to 100px and show up on the screen. In firefox, I get an obnoxiously large number for the top value like -1084px.

When I output both the .offset() values and position() values to console.log, they are the same in chrome. However in firefox, while the offset value outputs exactly what I set it to, the .position() function outputs the obnoxiously large number.

Is this a known browser inconsistency? Do I need to go about this a different way?

  • 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-06-01T06:51:03+00:00Added an answer on June 1, 2026 at 6:51 am

    Try setting your initial position as

    $('#modalContainer').height(document.documentElement.clientHeight);
    

    That should get you the height of the viewport.

    As an alternative to calculating your offset every time you could do use margin: auto and position: absolute on your alert box. You’ll still probably want to set the modal container height, but all the alert’s centering will be done automatically.

    HTML

    <body>
    <p>Lorum ipsum ... </p>
    <div id='modalContainer'>
        <div id='alertBox'>
            <h1>Beware!</h1>
        </div>
    </div>
    </body>
    

    CSS

    #modalContainer {
        position: absolute;
        width: 100%;
        margin: 0;
        padding: 0;
    }
    #alertBox {
        width: 300px; /*sample*/
        height: 200px; /*sample*/
        position: absolute;
        margin: auto;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    }
    

    JavaScript

    $('#modalContainer').height(document.documentElement.clientHeight);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create custom function for Main Nav menu where I can
I'm trying to create custom attributes to my button but I dont know which
I'm trying to fire custom events using jquery but for some reason I can't
I am trying to create custom Check Box button image. After some research, I
I am trying create my custom Style spinner with help of this site. But
Im trying to create a custom version of the RequiredAttribute to replace the built
I'm trying to create a custom JSP tag that would take an array object
I am trying to create a custom accordion for my page to that display
I'm trying to create a custom transition, to serve as a replacement for a
I'm trying to create a custom control - a button - which will have

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.