【问题标题】:Trying to center my web page [duplicate]试图使我的网页居中[重复]
【发布时间】:2011-11-26 23:59:33
【问题描述】:

可能重复:
page will not align center

我正在尝试使用 asp.net 使我的网页居中。当我使用 <center> 标签时,它只将内容占位符居中。但是当我使用 CSS 属性 margin: 0 auto 时,它什么也没做。有没有办法让整个页面居中?

【问题讨论】:

  • 您应该包含一些重现问题的示例 HTML。
  • 看不到您的代码。 margin: 0 auto; 仅适用于具有固定宽度的元素。
  • 这个问题已经有很多答案了。见:stackoverflow.com/questions/403736/…

标签: asp.net css margin center


【解决方案1】:
【解决方案2】:

在您的 CSS 中:

body {
    text-align: center;
}

#container {
    width: 900px; /* or some other fixed-width value */
    margin: 0 auto;
    text-align: left; /* reset text-align */
}

编辑:我猜我可能也应该显示相关的标记......

...
<body>
    <div id="container">
        <!-- centered content here -->
    </div>
</body>
...

【讨论】:

    【解决方案3】:

    您需要将所有内容包含在一个包装 div 中,并在该元素上设置宽度,以及 margin: 0 auto;

    例子:

    #wrapper {
      width: 960px;
      margin: 0 auto;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-04
      • 2012-11-22
      • 2021-10-20
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 2015-09-09
      • 2015-01-05
      相关资源
      最近更新 更多