如何为页面主体(html)留边距?

新手上路,请多包涵

我使用了以下

<body topmargin="0" leftmargin="0" rightmargin="0">

仅适用于 IE6。我希望它能与 Firefox 和 Opera 一起使用。

我尝试了以下操作:

 <style type="text/css">
.header {
    width: 100%;
    background-color: #3B5998;
    height: 35px;
    margin-top:0;
}
.style1 {
    margin-right: 38px;
}
.style2 {
    width: 100%;
    background-color: #3B5998;
    height: 35px;
}

</style>

 <div dir="rtl" class="style2" style="width: 100%">
<p align="center"style="width: 92px; height: 32px; font-family: Arial, Helvetica, sans-serif; font-size: 20px; color: #EFF1F6;" class="style1"></p>
</div>

</body>

原文由 Buffon 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 270
2 个回答

一开始你可以使用:

 <body style="margin:0;padding:0">

一旦你学习了一些关于 css 的知识,你就可以将其更改为:

 body {margin:0;padding:0}

在你的样式表中。

原文由 Damb 发布,翻译遵循 CC BY-SA 3.0 许可协议

是的,CSS 入门不会在这里受到伤害,因此您可以做两件事:1 - 在您的 html 标签中,您可以打开这样的样式标签:

 <style type="text/css">
  body {
   margin: 0px;
  }
  /*
   * this is the same as writing
   * body { margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;}
   * I'm adding px here for clarity sake but the unit is not really needed if you have 0
   * look into em, pt and % for other unit types
   * the rules are always clockwise: top, right, bottom, left
  */
</style>

2- 以上仅适用于您嵌入此代码的页面,因此如果您想在 10 个文件中重复使用此代码,则必须将其复制到所有 10 个文件中,并且如果您想进行更改假设有 5px 的边距,您将不得不打开所有这些文件并进行编辑。这就是为什么使用外部样式表是前端编码的黄金法则。因此,将正文声明保存在一个名为 style.css 的单独文件中,然后将其添加到您的 html 中:

 <link rel="stylesheet" type="text/css" href="style.css"/>

现在您可以将它放在所有将受益于这些样式的页面中,并且无论何时需要更改它们,您只需在一个地方进行。希望能帮助到你。干杯

原文由 Ady Ngom 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题