css居中的内容向左或向右移动

时间:2022-11-04 14:22:06

I have a html where the content is centered using the classic method:

我有一个html,其中内容使用经典方法居中:

width: 960px;
margin: 0 auto;

Now depending on the height of the content on a page a scroll bar might be shown. which will make the content to be centered in an area a bit smaller.

现在,根据页面上内容的高度,可能会显示滚动条。这将使内容在一个更小的区域中居中。

So in effect the content will just jump left or right.

所以实际上内容只会向左或向右跳。

The solution that i have is overflow-y: scroll; on body, which will always show the scroll bar.

我的解决方案是溢出:滚动;在body上,它将始终显示滚动条。

But if you mostly have small pages, you get an unused scrollbar all the time.

但是如果你大多数都有小页面,你会一直得到一个未使用的滚动条。

Are there any better solutions to this?

有没有更好的解决方案呢?

Thanks.

谢谢。

1 个解决方案

#1


0  

you could either remove the scrollbars:

你可以删除滚动条:

body, html {
    overflow: hidden;
}

Or (and still hiding the scrollbars), go for a javascript solution to add scrollbars inside the block you want, that way it won't shift the content.

或者(并且仍然隐藏滚动条),转到一个javascript解决方案,在你想要的块中添加滚动条,这样就不会改变内容。

#1


0  

you could either remove the scrollbars:

你可以删除滚动条:

body, html {
    overflow: hidden;
}

Or (and still hiding the scrollbars), go for a javascript solution to add scrollbars inside the block you want, that way it won't shift the content.

或者(并且仍然隐藏滚动条),转到一个javascript解决方案,在你想要的块中添加滚动条,这样就不会改变内容。