英文:
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?
.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?
<!-- 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 -->
<div class='headbar'>
<h1> Title </h1>
</div>
<!-- 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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论