当浏览器滚动条出现和消失时,保持网页居中 [英] Keeping a web-page centered when browser scroll bar appears and disappears

查看:495
本文介绍了当浏览器滚动条出现和消失时,保持网页居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得很基本的问题。我有一个网站,其中一些页面可能适合在浏览器的可见垂直区域,其他人不会(很多网站必须是这样)。



当用户在桌面浏览器上从一个页面浏览到另一个页面时,垂直滚动条因此显示和消失,具体取决于页面。这种影响是,当用户只是选择另一个导航链接时,很好地居中的页面继续移动滚动条的宽度 - 什么是阻止这种情况发生的最简单的方法,而不是使我的所有网页的高度相同? p>

第二部分 - 为什么桌面浏览器不只是保留垂直滚动条区域,也许有一种方法强迫他们?

解决方案

这样做(与IE6不兼容):

  body {overflow-y:scroll; } 

如果您还想显示水平滚动条,请使用:

  body {overflow:scroll; } 


Very basic question I think. I have a website where some pages are likely to fit within the viewable vertical area of the browser, and others won't (a lot of sites must be like this).

When users browse from one page to another on the desktop browser, the vertical scroll-bar therefore appears and disappears, depending on the page. The affect, is that the nicely centered page keeps on shifting by the width of the scroll-bar when the user just selects another navigation link - what's the easiest way to stop this happening, without making all my web pages the same height?

Second part - why do desktop browser not just reserve the vertical scroll-bar area, perhaps there's a way to force them?

解决方案

This does it (doesn't work with IE6):

body { overflow-y: scroll; }

If you also want to always show the horizontal scroll bar, use this:

body { overflow: scroll; }

这篇关于当浏览器滚动条出现和消失时,保持网页居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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