CSS 边距:自动在 IE 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7810326/
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-30 01:55:22  来源:igfitidea点击:

Margin: Auto not working in IE

cssinternet-explorerinternet-explorer-9margintext-align

提问by Lewes

URL: http://cyberbat.co.uk/testcontainer margin: auto is not working, is there any other way to put it in the middle in IE.

URL: http://cyberbat.co.uk/testcontainer margin: auto 不工作,有没有其他办法把它放在IE的中间。

EDIT: Check it again, the index.php was the wrong file, I replaced it with index.html .

编辑:再次检查, index.php 是错误的文件,我用 index.html 替换了它。

回答by ravy amiry

This is a bug in IE! You just need to create a holder for <div class="page">and set its text-alignto center

这是 IE 中的错误!您只需要为其创建一个持有人<div class="page">并将其设置text-aligncenter

.page-holder{
    text-align:center;
}
.page{
    margin:0 auto;
}
<div class="page-holder">
    <div class="page">
    page content
    </div>
</div>

回答by Jan Tojnar

Use this on parent container for stupid browsers:

在愚蠢浏览器的父容器上使用它:

text-align: center

回答by Co?kun GEM?C?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Your problem is define your file type and standards. if you add to this code to top of your file it will work!

您的问题是定义您的文件类型和标准。如果您将此代码添加到文件顶部,它将起作用!

回答by Daryl H

try using the following on the parent item.

尝试在父项上使用以下内容。

display: flex;
align-items: center;

回答by meder omuraliev

You have RAW php code because you didn't configure the server properly:

您有 RAW php 代码,因为您没有正确配置服务器:

<?php
include('inc/settings.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Resolve that issue by applying PHP to *.html files and <?php include ?>won't show up literally. If I recall correctly, adjust this line in the .ini file to be:

通过将 PHP 应用于 *.html 文件来解决该问题,并且<?php include ?>不会按字面显示。如果我没记错的话,将 .ini 文件中的这一行调整为:

AddType application/x-httpd-php .html .htm .php

Because this literal backend code is in front of the DOCTYPE, it causes quirks mode in IE and in quirks horizontal auto margins don't work properly.

因为这个文字后端代码在 DOCTYPE 之前,它会导致 IE 中的怪癖模式和怪癖水平自动边距无法正常工作。

You can go with the text-align:center on parent element, but that's a hack for IE and you should solve this properly by making IE render it in standards mode from my suggestion above.

你可以在父元素上使用 text-align:center ,但这对 IE 来说是一个黑客,你应该通过让 IE 根据我上面的建议以标准模式呈现它来正确解决这个问题。

回答by Sudhanshu Singh

For IE, replace my-auto with align-self-center and BINGO. You can also write CSS for the same:

对于 IE,将 my-auto 替换为 align-self-center 和 BINGO。您还可以为此编写 CSS:

.center-container{
   align-self: center;
}

回答by duri

Internet Explorer displays your website in quirks mode because of this bogus processing instruction at the top of markup:

由于标记顶部的这条虚假处理指令,Internet Explorer 以 quirks 模式显示您的网站:

<?php
include('inc/settings.php');
?>

Remove it; margin: autoworks in IE6+. There's noneed to do text-align: centeror other unnecessary changes.

去掉它; margin: auto适用于 IE6+。有没有必要做text-align: center或其他不必要的改动。

回答by tulsluper

Try adding a metarecord to head:

尝试将meta记录添加到head

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

回答by n4ks

You can download normalize.css (just google it) and link it to your project, now you can use smth like:

您可以下载 normalize.css(只需 google)并将其链接到您的项目,现在您可以使用 smth 如下:

HTML:

HTML:

    <main class="container></main>

CSS:

CSS:

    .container {
      margin-left: auto;
      margin-right: auto;
      width: 600px;