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 8396349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:30:53+00:00 2026-06-09T20:30:53+00:00

I found this jQuery code that allows to center a div that doesn’t have

  • 0

I found this jQuery code that allows to center a div that doesn’t have fixed dimensions both horizontally and vertically. It works with the window height and width. So when I resize the window, the div is still centered within the window.

My issue is that, right now, it doesn’t work unless I resize the window first. So if I just load the page, the div isn’t centered unless I manually resize the window.

This, of course, is not ideal. So I’m trying to find a way around it. But my jQuery skills being very limited I’m stuck right now.

Here’s the page I’m working on: http://dev.manifold.ws/test2/ (try resizing the window to see what I’m describing)

And here’s the jQuery I’m using:

$(document).ready(function(){

$(window).resize(function(){

    $('.img-holder').css({
        position:'absolute',
        left: ($(window).width() - $('.img-holder').outerWidth())/2,
        top: ($(window).height() - $('.img-holder').outerHeight())/2
    });

});
// This is suppose to initially run the function but it doesn't seem to work
$(window).resize();

});

Does anyone have an idea of how to fix this?
Thanks!

-Thom

  • 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-09T20:30:54+00:00Added an answer on June 9, 2026 at 8:30 pm
    $(document).ready(function(){
        doResize();
        $(window).on('resize', doResize);
    });
    
    function doResize() {
        $('.img-holder').css({
            position:'absolute',
            left: ($(window).width() - $('.img-holder').outerWidth())/2,
            top: ($(window).height() - $('.img-holder').outerHeight())/2
        });
    }
    

    FIDDLE

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

Sidebar

Related Questions

I am hoping that someone can help me. I have found this jquery script
I found this HOT bit of jQuery that actually allows you to replicate font-variant:
noob here i got this jquery code that i found on stackoverflow var maxLines
I've found this useful bit of code that allows uk dates to work in
I have this script that I found which allows me to have userside Ajax
I found this jQuery code on a forum: http://jsfiddle.net/nZLpk/8/ However, if I change the
Hi I found the following code from this page JQuery UI DatePicker using 2
I found this jQuery plugin online that shows and hides divs. It's perfect for
I have found and customized this JQuery script, which displays different content when different
I found a jQuery code which allows me to check id a certain radio/checkbox

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.