【问题标题】:How to insert a margin at the right and left of the page?如何在页面的左右插入边距?
【发布时间】:2009-10-26 22:54:03
【问题描述】:

我想插入这个边距,但我不知道为什么...我希望它像 Twitter 或 TwitPic

我的 CSS:

 body {
        margin: 40px;
        margin-bottom: 50px;
        padding: 0;
        background-color: #edece9;
        font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
        font-size: 13px;
        color: #333;
      }

【问题讨论】:

  • 你粘贴的代码看不懂,使用代码标签

标签: html css margin


【解决方案1】:

假设页面结构如下:

<!DOCTYPE html>
<html>
  <head>
    <link type="text/css" rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div id="main">
    </div>
  </body>
</html>

那么 style.css 应该是这样的:

* {margin:0;}
div#main {
  width:800px;
  margin:0 auto;
}

【讨论】:

    【解决方案2】:

    twitter 使用固定宽度的 div,它使用 margin-left:auto;margin-right:auto。这将使 div 水平居中

    【讨论】:

      【解决方案3】:

      你需要放置一个带有固定的 div (你想要的页面宽度并把它的margin:0 auto

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-07
        • 1970-01-01
        • 2016-09-29
        • 2018-08-09
        • 1970-01-01
        • 2016-09-23
        相关资源
        最近更新 更多