Html 水平对齐在Internet explorer中无法正常工作
我正在尝试使用位置垂直对齐div。它在除Internet Explorer之外的所有浏览器中都能正常工作。在internet explorer中,Html 水平对齐在Internet explorer中无法正常工作,html,css,internet-explorer,Html,Css,Internet Explorer,我正在尝试使用位置垂直对齐div。它在除Internet Explorer之外的所有浏览器中都能正常工作。在internet explorer中,.nav组向左对齐。我怎样才能解决这个问题 HTML: <div class="container"> <div class="nav-group">// Content</div> </div> .container { width: 100%; position: relative; }
.nav组
向左对齐。我怎样才能解决这个问题
HTML:
<div class="container">
<div class="nav-group">// Content</div>
</div>
.container
{
width: 100%;
position: relative;
}
.nav-group
{
display: table;
background-color: red;
margin: auto;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:0;
right:0;
}
对于可能不起作用的同一div,您正在使用
Position:absolute
和margin:auto
。所以我修改如下:
.container {
width: 100%;
text-align:center;
}
.nav-group {
display:table;
background-color: red;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:50%;
margin-left:-100px;
right:0;
}
.nav-group
{
display: block;
background-color: red;
margin: auto;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:0;
right:0;
}
您可以使用显示:表格代码>在这里它不会影响任何东西
我在IE 10中测试,最新版本的firefox和chrome。。工作正常。将display:table更改为display:inline
.nav-group { display:inline}
希望这能帮助你
.container {
width: 100%;
text-align:center;
}
.nav-group {
display:table;
background-color: red;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:50%;
margin-left:-100px;
right:0;
}
.nav-group
{
display: block;
background-color: red;
margin: auto;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:0;
right:0;
}
css:
您使用绝对定位的事实正在影响您的布局。您可以选择更改绝对位置和使用margin:0 auto
。或者更改您为元素提供的显示
更改显示:表格代码>至<代码>显示:块代码>
或
删除显示:表格代码>也工作
.container {
width: 100%;
text-align:center;
}
.nav-group {
display:table;
background-color: red;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:50%;
margin-left:-100px;
right:0;
}
.nav-group
{
display: block;
background-color: red;
margin: auto;
width: 200px;
height: 100px;
position: absolute;
bottom: 50px;
left:0;
right:0;
}
你试过margin:0 auto吗?@Amit,没试过运气。你能制作一个演示吗?我想如果你改变display:table编码>至显示:表格单元格代码>它可能会工作。我需要显示:表;必选。必须显示:表格。