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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:39:20+00:00 2026-05-31T06:39:20+00:00

I have a horizontally centered div #box1 that has margin: 5px auto that has

  • 0

I have a horizontally centered div #box1 that has margin: 5px auto that has to slide to the left and off the screen, while #box2 slides into the screen from the right, when the button .class is clicked on. I’ve seen how its done for absolutely positioned divs, now how do you do it if its not?

HTML Structure

<div class="button"><a href="#">Slide</a> </div>

<div id="container">

    <div id="box1" class="box">Box #1</div>
    <div id="box2" class="box">Box #2</div>

</div>

Failed attempt

$(".button").click(function() {
    $("#box1").css('margin-left', 0);
    $("#box1").css('margin-right', 0);
    $("#box1").animate({
            left: '150%',
        }, 'slow' );

});
  • 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-31T06:39:21+00:00Added an answer on May 31, 2026 at 6:39 am

    Is this the effect you’re looking for: jsFiddle example.

    jQuery:

    $(".button").click(function() {
        $("#box1").css('margin-left', 0);
        $("#box1").css('margin-right', 0);
        $("#box1").animate({ left: '-500px' }, 'slow');
        $("#box2").animate({ left: '0px' }, 'slow');
    });​
    

    CSS:

    #box1, #box2 {
        margin: 5px auto;   
        border: 1px solid #999;
        position:relative;
    }
    #box2 {
       left:500px;   
    }
    #container {
        overflow:hidden;
    }
    

    ​
    HTML:

    <div class="button"><a href="#">Slide</a> </div>
    <div id="container">
        <div id="box1" class="box">Box #1</div>
        <div id="box2" class="box">Box #2</div>
    </div>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element on the page that I've already centered horizontally and vertically
I have a div ( #main ) that has been centred to the middle
I want a horizontally centered floating div, i.e. one that always is on top
ive created a lightbox where I have centered the div horizontally and vertically with
I have an unlimited/unbound number of DIV tags that are floating to the left.
The <center>Text</center> tag to have text centered horizontally is depreciated, so I tried <p
I have one horizontally div on the top of my page with a height
I have a UIScrollView that contains multiple UITableViews horizontally - all of which are
I have a ListView where I would like to display things horizontally. That works
I have a UniformGrid object in my WPF project that has 2 rows 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.