默认 <body> 边距是多少?

htmlweb developmentfront end technology更新于 2024/6/6 15:08:17

HTML 中,默认 <body> 边距为 8px。它由浏览器提供的用户代理样式表(以像素为单位)定义。某些浏览器允许您创建和使用自己的用户代理样式表,但如果您正在开发网站,请保持其不变。

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>

您可以轻松比较上述两个示例并发现边距差异。


相关文章


有用资源