Small margin left when div width defined to be 100%

huangapple go评论65阅读模式
英文:

Small margin left when div width defined to be 100%

问题

I'm trying to make a fairly simple website and so far all I have is the top title bar. For some reason, there is a small margin on the left side. Any idea why and how to fix it?

Small margin left when div width defined to be 100%

.headbar {
  background-color: #117FF2;
  position: fixed;
  top: 0;
  width: 100%;
  margin: 0 auto;
  padding: 0;
}
<div class='headbar'>
  <h1> Title </h1>
</div>
英文:

I'm trying to make a fairly simple website and so far all I have is the top title bar. For some reason, there is a small margin on the left side. Any idea why and how to fix it?

Small margin left when div width defined to be 100%

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.headbar {
  background-color: #117FF2;
  position: fixed;
  top: 0;
  width: 100%;
  margin: 0 auto;
  padding: 0;
}

<!-- language: lang-html -->

&lt;div class=&#39;headbar&#39;&gt;
  &lt;h1&gt; Title &lt;/h1&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 3

我认为这可能是由于body元素的默认边距引起的。

尝试这样做:

body {
  margin: 0;
}
英文:

I think it's probably caused by the default margin of the body element.

Try this:

body {
  margin: 0;
}

huangapple
  • 本文由 发表于 2023年4月19日 14:35:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76051399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定