[英]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. 有人单击“此处”后,我希望div移动到屏幕左侧的水平中心,并且div
出现并显示在屏幕右侧,同时也保持水平居中。 Here is my code 这是我的代码
Use top and left. 使用顶部和左侧。
#wrapper {
left: 50%;
position: absolute;
margin-left: -223px /* half of width*/
}
Then animate div using: 然后使用以下方法对div进行动画处理:
$('button[name="whattoput"]').click(function () {
$('div').animate({
left: "323px" // target position + left margin
});
});
check this please make position of #wrapper to relative 检查一下,请将#wrapper的位置相对
.hidestuff {
//display: none;
}
#wrapper {
margin-left:auto;
margin-right:auto;
width: 445px;
position:relative;
}
http://jsfiddle.net/rut2/cvp6eg0t/6/ http://jsfiddle.net/rut2/cvp6eg0t/6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.