中心div在屏幕上,不工作在IE11上,但它在Firefox中工作
问题描述:
使用CSS,我试图将div Wrapper放在屏幕上。它适用于Mozilla,但它不适用于IE 11.我不知道为什么。我的网页是在Windows Server 2008上运行中心div在屏幕上,不工作在IE11上,但它在Firefox中工作
CSS
div#wrapper
{
width: 1250px;
min-width:1250px;
max-width:1250px;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom:0;
margin-left: auto;
margin-right: auto;
margin: auto;
border: 2px solid red;
}
ASPX:网页在Mozilla
<head runat="server">
<title></title>
<link href="Styles/Site.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div id="wrapper">
HELLO
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
IE11中的网页图像。正如你看到的,DIV是不是在屏幕居中:
答
试试这个:
body
{
width:100%;
height: 100%;
}
div#wrapper
{
width: 1250px;
min-width: 1250px;
max-width: 1250px;
position: absolute;
top:0;
bottom:0;
left: calc(50% - 625px);
border: 2px solid red;
}
编辑:我测试,它在IE11的作品。
解释代码:它会将div放在body标签内部的身体宽度减去625px(div宽度的一半)的50%处,该宽度是浏览器宽度的100%。
你应该在IE11中工作。可能还有其他相互冲突的风格。 –