Html 如何在CSS中将10000px(比全屏宽)的div水平居中?

Html 如何在CSS中将10000px(比全屏宽)的div水平居中?,html,css,Html,Css,如何在CSS中水平居中放置10000px(或其他比全屏更宽)的div e、 g 在这种情况下,“边距:0自动”似乎不起作用 position: absolute; left: 50%; margin-left: -5000px; 尝试添加类似于 position: absolute; left: 50%; margin-left: -5000px; 这么宽的宽度真是太可笑了。。我有两个解决方案 利润率不起作用,因为它没有什么可调整的,所以这里有两种可能性 第一种解决方案:使用div包装它。代

如何在CSS中水平居中放置10000px(或其他比全屏更宽)的div

e、 g

在这种情况下,“边距:0自动”似乎不起作用

position: absolute;
left: 50%;
margin-left: -5000px;
尝试添加类似于

position: absolute;
left: 50%;
margin-left: -5000px;

这么宽的宽度真是太可笑了。。我有两个解决方案

利润率不起作用,因为它没有什么可调整的,所以这里有两种可能性

第一种解决方案:使用div包装它。代码如下:

<div id="wrapper">
    <div id="widerdiv"></div>
</div>
第二个解决方案:定义你的身体宽度。和下面的代码(这只是CSS,因为我不会修改您的HTML):

现在,通过一切必要的手段,您可以将该宽度设置为您想要的最大宽度(天堂禁止水平滚动…),但是如果您使用这些JSFIDLE,您将意识到您绝对需要定义该Div内部的宽度

最后,在这一次中,他将是你的朋友。作为一个简单的例子,如果你决定尝试垂直定位,这就是当你使用'margin:0auto;'在CSS中:

"The element is given a specified width
The left and right margins are set to auto
Without the specified width, the auto values would 
essentially have no effect, setting the left and right 
margins to 0 or else to whatever is the available space 
inside the parent element.

It should also be pointed out that auto is useful 
only for horizontal centering, and so using auto for
top and bottom margins will not center an element horizontally, 
which can be confusing for beginners."

上面的引文在年鉴中也有引用。

宽度如此之大,实在是荒谬。。我有两个解决方案

利润率不起作用,因为它没有什么可调整的,所以这里有两种可能性

第一种解决方案:使用div包装它。代码如下:

<div id="wrapper">
    <div id="widerdiv"></div>
</div>
第二个解决方案:定义你的身体宽度。和下面的代码(这只是CSS,因为我不会修改您的HTML):

现在,通过一切必要的手段,您可以将该宽度设置为您想要的最大宽度(天堂禁止水平滚动…),但是如果您使用这些JSFIDLE,您将意识到您绝对需要定义该Div内部的宽度

最后,在这一次中,他将是你的朋友。作为一个简单的例子,如果你决定尝试垂直定位,这就是当你使用'margin:0auto;'在CSS中:

"The element is given a specified width
The left and right margins are set to auto
Without the specified width, the auto values would 
essentially have no effect, setting the left and right 
margins to 0 or else to whatever is the available space 
inside the parent element.

It should also be pointed out that auto is useful 
only for horizontal centering, and so using auto for
top and bottom margins will not center an element horizontally, 
which can be confusing for beginners."

上述引文也在年鉴中引用。

为什么是10000?这是一个非常大的数字!!你想把它放在哪里?在另一个舱里?在HTML文本的主体标记中?与div的大小相同。您没有看到差异的原因可能是您无法正确检出。有什么比在浏览器中水平滚动更糟糕的吗?@rickhg12hs是的!有。缩放和水平滚动在一起。你的意思是div的中心应该在屏幕的中心吗?(这意味着div的左侧被切断,无法滚动到。)或者屏幕应该水平滚动到div的中心?当内容比屏幕宽时,这些是“水平居中”唯一有意义的例子。为什么是10000?这是一个非常大的数字!!你想把它放在哪里?在另一个舱里?在HTML文本的主体标记中?与div的大小相同。您没有看到差异的原因可能是您无法正确检出。有什么比在浏览器中水平滚动更糟糕的吗?@rickhg12hs是的!有。缩放和水平滚动在一起。你的意思是div的中心应该在屏幕的中心吗?(这意味着div的左侧被切断,无法滚动到。)或者屏幕应该水平滚动到div的中心?当内容比屏幕宽时,“水平居中”是唯一有意义的情况。