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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:26:57+00:00 2026-05-28T05:26:57+00:00

I have a div $(#organizer_listings_container) initially centered using CSS margin: 0 auto; which uses

  • 0

I have a div $("#organizer_listings_container") initially centered using CSS margin: 0 auto; which uses jQuery to increase its width when the user clicks on a button. After resizing, I’m using the following code to center this resized div $("#organizer_listings_container").

Resizing code

// Center content when width changes
if($("#organizer_listings_container").css("position") != 'absolute') {
    $("#organizer_listings_container").css("position","absolute");
    var left = ( $(window).width() - $("#organizer_listings_container").width() ) / 2 + "px";
    $("#organizer_listings_container").css('left', left);       // set initial 'left'
}
left = ( $(window).width() - ( 852 ) ) / 2  + "px";
$("#organizer_listings_container").animate({'left': left}); // animate to final 'left'  

Problem: When I add a new div (make it visible using jQuery show()), it appear above #organizer_listings_container, #organizer_listings_container shifts downwards which is correct. Now when I remove this newly added div, #organizer_listings_container does not shift back up!

I suspect this is due to the absolute positioning required by the jQuery centering code that was used. How can I make the resized div shift back up when the newly added div is removed?

Using jQuery to calculate the height of the newly added div then shifting the resized div up by offsetting the top by the calculated height appears to be messier than I want

  • 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-28T05:26:58+00:00Added an answer on May 28, 2026 at 5:26 am

    You can avoid having to use jquery and add a class to the newly added div and centre it with a top displacement like so:

    <div class="container" style="background:blue; width:100%;">
    <div class="box" style="background:green; width:50px; height:40px; margin: 0 auto; margin-top:20px;"></div>
    </div>
    

    Note that the class would contain the inline style, this is just for an example.

    The only thing you might need jquery for would be to ensure that the container was 100% the height. But if you’re only going to see the box and you’re only using the container for positioning it centered, then you don’t need this requirement.

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

Sidebar

Related Questions

I have Div Container with css class: .content4 { height: 1400px; width: 920px; border:
I have div with the following css style: width:335px; float:left; overflow:hidden; padding-left:5px; When I
I have a div in which a page is loaded with the DojoX Layout
I have a div with overflow:hidden , inside which I show a phone number
I have a div container and have defined its style as follows: div#tbl-container {
I have a div tag styled through CSS. I set the padding to 10px
I have div(box) on my page and I'm using this script to display div
I have div with height=400px and width=25px.How to expand div when the content overflows?
I have next problem: There is jquery accordion control. One of tab have div
I have the following code in my CSS file, which isn't working. #home table

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.