0

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
  • It is the p tag of the browser causing this. jsfiddle.net/gpdeoL1v/6 Use a browser reset css instead for a cleaner fix. Commented Oct 5, 2014 at 23:16

2 Answers 2

0

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;
}
Sign up to request clarification or add additional context in comments.

Comments

0

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;
}

1 Comment

Worked like a charm! I think I mistook what margins do. I thought that it controls the outer margin instead the inner margin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.