Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
internet explorer中的HTML Div中心对齐_Html_Css_Internet Explorer - Fatal编程技术网

internet explorer中的HTML Div中心对齐

internet explorer中的HTML Div中心对齐,html,css,internet-explorer,Html,Css,Internet Explorer,我已经编写了以下代码。它在Mozilla和Chrome中表现得非常出色。但在Internet Explorer中,它不是居中对齐的,而是显示在左侧。代码如下: <html> <head> <title>ProgramEngine Website Registration</title> <style type="text/css"> div#login { background-color:#f1f1f1; width: 510px;

我已经编写了以下代码。它在Mozilla和Chrome中表现得非常出色。但在Internet Explorer中,它不是居中对齐的,而是显示在左侧。代码如下:

<html>
<head>
<title>ProgramEngine Website Registration</title>
<style type="text/css">
div#login
{
background-color:#f1f1f1;
width: 510px;
height: 1024px;
border: 1px solid grey;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="login"></div>
</body>
</html>

程序引擎网站注册
div#登录
{
背景色:#f1f1;
宽度:510px;
高度:1024px;
边框:1px纯灰;
左边距:自动;
右边距:自动;
}

那么,有人能告诉我问题是什么以及如何克服它吗。

您使用的是正确的DOCTYPE吗?如果没有DOCTYPE,IE会自动进入怪癖渲染模式-这可能是您的问题。

您可以使用jquery获得好的解决方案

如果需要,请使用顶部偏移值


在这里,浏览器不会出问题。

您指的是哪个版本的internet explorer?这对我在IE7+中的工作很好,我看不出你的代码可能会导致任何明显的问题。你在测试哪个版本的IE?它似乎在IE7+中工作良好。在IE中工作良好。我有一个想法。你能使用jquery吗?@KarSho,没有必要-这在IE中可以正常工作。我怀疑你在其他地方有一些CSS正在重置你的声明。IE(所有版本)支持什么DOCTYPE?使用例如HTML 5 DOCTYPE。
$(document).ready( function(e){    
        var screen = $('body').width();
        screen -= 51;  //51 is width of div
        screen /= 2;
        $('#login').offset({top:0,left:screen});
    });​