【问题标题】:html - div on the centrhtml - 居中的 div
【发布时间】:2010-11-27 23:04:24
【问题描述】:

如何将 div 的位置设置在页面的中心,大小,例如 80%/80%。

UPD:边距:0自动;有效,但仅适用于水平对齐。而且我还需要垂直。

【问题讨论】:

标签: html center


【解决方案1】:

page 讨论了一些使用 css 实现垂直居中的不同方法。我以前成功地使用过方法 2,但我认为所有这些充其量都是 hack。

【讨论】:

    【解决方案2】:

    设置固定宽度和自动边距。

    <style type="text/css">
    #center {
      width:300px;
      margin-left:auto;
      margin-right:auto;
    }
    </style>
    
    <body>
    <div id="center"></div>
    </body>
    

    【讨论】:

    • 我知道这一点。我想这样做不仅适用于侧面......而且适用于顶部和底部。
    【解决方案3】:

    这是你想要的,但它并不漂亮。

    <div style="margin: 0 auto;width:80%;height:80%;">
    This will probably not work for you however because you did not provide code
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-29
      • 2017-06-19
      • 1970-01-01
      • 2013-07-29
      • 2014-06-11
      • 2012-12-12
      • 2023-04-06
      • 2017-02-28
      相关资源
      最近更新 更多