如何使用 Internet Explorer 将 div 居中?
我在使用 Internet Explorer 和居中时遇到问题,我的问题是如何在没有 CENTER 标签的情况下使 div 居中 它可以在所有浏览器中工作, 因为我正在使用
margin:auto;
它适用于所有浏览器 但它在 Internet Explorer 中不起作用 我正在寻找适用于所有浏览器的东西 有人告诉我要放在
text-align: center;
正文中,但所有文字都放在中间,
所以我该怎么做?
i have trouble with internet explorer and centering , my question is how can i centering a div without the CENTER tag
and it got to work in all the browsers ,
because i was using
margin:auto;
it works in all borwsers
but it does not work in internet explorer
i'm looking for something that will work in all the browsers
someone told me to put
text-align: center;
to the body but than all the text has go to the middle
so how can i do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你很接近了。使用下面的 CSS:
这是一个工作的 jsFiddle。请注意,我给了 div 一个固定的宽度。
You're close. Use the CSS below:
Here's a working jsFiddle. Note that I gave the div a fixed width.
您需要指定宽度和边距:
示例 HTML:
You need to specify a width as well as margin:
Example HTML:
IE 对自动边距的支持不稳定(即,怪异模式下的不同行为)。这应该适用于几乎所有情况:
CSS:
HTML:
IE has spotty support for auto margins (i.e., different behavior in quirks mode). This should work in pretty much all cases though:
CSS:
HTML:
是的,这在 IE 中完美运行。
Yes this works perfectly in IE.
你的CSS很接近,你的问题不是浏览器。简单的修复方法是更改内部 div 类。
您的位置绝对为 Left 25%...使用 Left 50%,它会自动更正。
完全删除 left: 50% 并添加 margin: 0 auto;正如之前在另一个答案中所指出的。
Your CSS is close, the your issue isn't the browser. The simple fix is to change the inner div class.
You have your position absolute with Left 25%... Use Left 50% and it will autocorrect.
Remove the left: 50% entirely and add margin: 0 auto; as previously noted on another answer.