默认边距的宽度是多少?


<body> 的默认边距在 HTML 中为 8 像素。它由浏览器提供的 user-agent-stylesheet 以像素为单位定义。某些浏览器允许您创建并使用您自己的 user-agent-stylesheet,但如果您正在开发网站,请保持不变。

HTML 中的默认边距

示例

让我们看一个简单的例子。由于此处默认的边距为 8px,因此我们不会尝试更改它 −

<!DOCTYPE html> <html> <title>Example</title> <head> <style> body { background: orange; } </style> <body> <h1>Free Resources</h1> <p>We have the following resources for the users:</p> <div id="container"> <ul> <li>Video Courses</li> <li>Notes</li> <li>Interview QA</li> <li>MCQs</li> </ul> </div> </body> </html>

在 HTML 中更改默认边距

示例

现在,让我们更改默认边距 −

<!DOCTYPE html> <html> <title>Example</title> <head> <style> body { background: orange; margin: 25px; } </style> <body> <h1>Free Resources</h1> <p>We have the following resources for the users:</p> <div id="container"> <ul> <li>Video Courses</li> <li>Notes</li> <li>Interview QA</li> <li>MCQs</li> </ul> </div> </body> </html>

您可以轻松比较以上两个示例并找出边距差异。

更新于: 2022-10-18

2K+ 浏览量

开启你的事业

通过完成课程获得认证

开始
广告
© . All rights reserved.