防止由于滚动条而导致重新布局 [英] Preventing relayout due to scrollbar

查看:237
本文介绍了防止由于滚动条而导致重新布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当由于ajax内容而出现滚动条时,如何防止页面正文被推"到左侧? 我当然可以将overflow:scroll设置到身体,但是看起来不太好.

How can I prevent the body of the page being "pushed" to the left when a scrollbar appears due to ajax content? I can of course set overflow:scroll to the body, but it wouldn't look nice.

我正在使用引导程序,但我想这是一个普遍的问题.

I am using bootstrap, but I guess it is a general question.

推荐答案

您可以创建一个具有固定宽度的容器,并为内容提供相同的宽度(相同的静态宽度-不是100%). 这样,当内容溢出父对象时,滚动将不会推送内容,但会在其上方流动.

You can create a container that have a fixed width, and give the content the same width (same static width - not 100%). that way, when the content overflows the parent, the scroll will not push the content but will flow above it.

使用它,您可以应用一种很酷的滚动方式,而无需执行任何操作.仅当您将鼠标悬停在容器上时才显示滚动.

using that, you can apply a cool way to scroll without pushing anything. by showing the scroll only when you hover the container.

查看这个简单的 演示

Check out this simple Demo

此处我展示了设置静态宽度和%之间的区别.

Here I show the difference between setting static width, and %.

这篇关于防止由于滚动条而导致重新布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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