为什么容器不在 Internet Explorer 中居中?

发布于 2024-10-22 10:06:33 字数 284 浏览 9 评论 0原文

我有我的作品集,在所有浏览器中看起来都很棒,但在 Internet Explorer 中,容器似乎没有居中,我正在使用 margin: 0 auto; 但它不起作用。如何在 Internet Explorer 中修复?

这是代码的链接: http://christianbovine.com/

I have my portfolio, looks great in all browsers but in Internet Explorer the container doesn't seem to center, I'm using margin: 0 auto; but it is not working. How can I to fix in Internet Explorer?

Here is the link to the code:
http://christianbovine.com/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬 2024-10-29 10:06:33

旧版本的 IE 需要不礼貌地使用文本对齐,如下所示:

<div style="text-align: center;">
    <div style="text-align: left; width: 300px; margin: 0 auto;">
        <p>Content goes here</p>
    </div>
</div>

添加宽度纯粹是为了参考,添加边距纯粹是为了跨浏览器兼容性。

对于你的情况,我建议添加第二个“容器”div(即containerInner),然后你可以在CSS中添加如下内容:

div#container { text-align: center; }
div#containerInner { text-align: left; }

Older versions of IE require the ingracious use of text-align, like so:

<div style="text-align: center;">
    <div style="text-align: left; width: 300px; margin: 0 auto;">
        <p>Content goes here</p>
    </div>
</div>

Width is added purely for reference, and margin purely for cross-browser compatibility.

In your case, I'd recommend adding a second "container" div (ie. containerInner), and you could then add something like this in CSS:

div#container { text-align: center; }
div#containerInner { text-align: left; }
明月夜 2024-10-29 10:06:33

在父元素中,使用“text-align”属性。例如:

body{
    text-align:center;
}

In the parent element, use the "text-align" attribute. For example:

body{
    text-align:center;
}
〆一缕阳光ご 2024-10-29 10:06:33

使用 text-align:center 作为正文标记或将所有内容包装在标记内。

另外,您可能需要考虑使用 display:inline-block。这允许您指定元素的宽度和高度属性(如果它只是设置为内联而不是块,则宽度和高度属性将被忽略)(如果是这种情况)。

Use text-align:center for the body tag or wrap all content inside a tag.

Also, you may want to consider using display:inline-block. This allows you to specify width and height properties for elements (if it's just set to inline and not block, width and height attributes are ignored) if it's the case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文