将屏幕左侧的div居中

时间:2014-12-05 09:02:55

标签: javascript jquery html css

enter image description here

一旦有人点击"在这里",我希望div移动到屏幕左侧的水平中心,并显示div并显示在屏幕的右侧同时也是水平居中的。 这是我的代码

My Code! jsbin

2 个答案:

答案 0 :(得分:0)

使用顶部和左侧。

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

然后使用:

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

答案 1 :(得分:0)

检查一下 请将#wrapper的位置设为亲戚

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

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