Html 在页面底部居中对齐文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8661033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:12:25  来源:igfitidea点击:

Align text centrally on the bottom of the page

htmlcss

提问by user1006115

I want to have a text aligned centrally on the bottom of the page.

我想让一个文本在页面底部居中对齐。

I have the following code:

我有以下代码:

<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div style="position: relative">
            <p style="position: fixed; bottom: 0; width:100%; text-align: center"> bla bla
            </p>
        </div>
    </body>
</html>

It works fine in Firefox and Chrome but not in IE.

它在 Firefox 和 Chrome 中运行良好,但在 IE 中不起作用。

回答by thirtydot

You need to add a doctype as the very first line:

您需要添加一个文档类型作为第一行:

<!DOCTYPE html>
<html>

Without it, IE is using Quirks Modewhich emulates IE 5.5 (which doesn't support position: fixed).

没有它,IE 将使用模拟 IE 5.5(不支持)的Quirks 模式position: fixed

回答by Robert

Might be a copy and paste issue but you need an ending quote in your <p style=... >, that should help. Another option is the set your text-align: centeron the actual <div>so your aligning the text inside the div. Both of these worked in IE 9 - what version of IE are you using that it's not working in?

可能是复制和粘贴问题,但您需要在您的<p style=... >. 另一种选择是设置您text-align: center的实际,<div>以便您对齐 div 内的文本。这两个都在 IE 9 中工作 - 您使用的是哪个版本的 IE 无法工作?

<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <div style="position: relative">
      <p style="position: fixed; bottom: 0; width:100%; text-align: center"> bla bla</p>
    </div>
  </body>
</html>

OR

或者

<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <div style="position: relative; text-align: center">
      <p style="position: fixed; bottom: 0; width:100%;"> bla bla</p>
    </div>
  </body>
</html>