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

DC1*_*DC1 1 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>
Run Code Online (Sandbox Code Playgroud)

有没有人有办法解决吗?

Pra*_*lan 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>
Run Code Online (Sandbox Code Playgroud)

小提琴演示