如何在滚动后放置窗口的div中心 [英] How to place a div center of the window after scrolling

查看:107
本文介绍了如何在滚动后放置窗口的div中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,它应该是窗口的中心,即使在滚动后。如何实现

I am having a div, which should be centre of the window, even after scrolling. How to achieve it

http://www.flickr.com/photos/41695354@N08/4496376638/

推荐答案

您可以它具有位于中心的固定宽度,并且具有带宽度的一半和高度的一半的负边距。因此,对于id your_div 大小为200x200的div,您可以这样做:

You can do it with a fixed width positioned in center and with negative margins with half of the width and half of the height. So for a div with id your_div that is 200x200 in size, you'd do:

#your_div {
    width: 200px;
    height: 200px;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-left: -100px;
    margin-top: -100px;
}

这篇关于如何在滚动后放置窗口的div中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆