Issue removing margin with HTML/CSS

房东的猫 提交于 2021-01-29 18:10:30

问题


I cannot seem to succeed to completely fill a horizontal space with a div. There is always a little space at the right, left, top and bottom.

JSFiddle

I am currently using:

CSS:

.section{
   width: 100%;
   display: inline-block;
   top: 0px;
   left: 0px;
   margin: 0px;
   padding: 0px;    
}
#section-1,#section-3{
   background-color: #ddd;    
}

HTML:

<div id="section-1" class="section">
  <p>Foo</p>
</div>

回答1:


Also put margin: 0 on body

body{
    margin: 0;
}

What is generally done is setting margin and padding both to 0 on both html and body to make it work perfectly cross-browser.

html, body{
    padding: 0;
    margin: 0;
}



回答2:


That's actually because of the margin for the body. Please check this fiddle. I've added this style to the CSS:

body {
    margin: 0px;
}


来源:https://stackoverflow.com/questions/26208187/issue-removing-margin-with-html-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!