简体   繁体   中英

Center a div on the left side of the screen

在此处输入图片说明

Once someone clicks "Here", I want the div to move to horizontally center of the left side of the screen and a div to appear and show up on the right side of the screen while being horizontally centered as well. Here is my code

My Code! jsbin

Use top and left.

#wrapper {
    left: 50%;
    position: absolute;
    margin-left: -223px /* half of width*/
}

Then animate div using:

$('button[name="whattoput"]').click(function () { 
    $('div').animate({
        left: "323px" // target position + left margin
    });
});

check this please make position of #wrapper to relative

.hidestuff {
    //display: none;
}
#wrapper {
margin-left:auto;
margin-right:auto;
width: 445px;
position:relative;
}

http://jsfiddle.net/rut2/cvp6eg0t/6/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM