如何水平居中只有最大宽度并具有固定位置的div?

时间:2014-01-31 02:09:24

标签: css css-position

我一直试图找到解决方案,一直在搜索论坛,但你唯一谈论百分比。

我有一个只包含文字的div。我需要它的最大宽度为700px,固定并在屏幕上水平居中。

在一个完美的世界里,这就是我想要的工作,但当然不会:

<div style="max-width: 700px; text-align: center; position: fixed; bottom: 40px; margin: auto;">sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text</div>

有没有人有解决方案?

1 个答案:

答案 0 :(得分:5)

设置left:0;right:0;

<div style="max-width: 700px; text-align: center; position: fixed; bottom: 40px; margin: auto;left:0;right:0;">sample text</div>

Fiddle Demo