I've set my div element to have some css rules. It has a width and height of 100px. It also has its padding, border, and margin set to 0px. What CSS default tells the code to offset the elements around 10px from the edges of the browser window? I know that my css styles are working because the division directly below the first one is touching it because of the zero margin.
Set element to have a width and height of 100px; padding, margin, and border set to 0px; why is it still offset?
Asked
Active
Viewed 136 times
0
-
did you set body element to margin:0; ?
– iliketolearn
Oct 15 '15 at 15:53
-
1
Post your code for a better help
– GmloMalo
Oct 15 '15 at 15:55
-
Possible duplicate of [CSS Margin: 0 is not setting to 0](http://stackoverflow.com/questions/5387576/css-margin-0-is-not-setting-to-0)
– Fundhor
Oct 15 '15 at 16:02
-
Yep, paste your code, probably with a screenshot of the calculated css styles or box model or something from the chrome / firefox / ie debugger
– cedd
Oct 15 '15 at 16:04
2 Answers
1
Add this at the top of your stylesheet:
body {
margin:0px;
padding:0px;
}
the body has some default padding
and margin
setting that to 0 will make the elements stick to the edges
Antonio Smoljan
- 2,187
- 1
- 12
- 11
0
Tip: you can always check with a element inspector
If you press f12
you can see it's element inspector. The gray parts of the inspector shows you which default styles are enabled.
The body always has a margin
of 8px
by default. To disable it just use:
body{
margin: 0px;
}
Tom Groot
- 1,160
- 1
- 9
- 26
Asked
Active
Viewed 136 times
0
-
did you set body element to margin:0; ? – iliketolearn Oct 15 '15 at 15:53
-
1Post your code for a better help – GmloMalo Oct 15 '15 at 15:55
-
Possible duplicate of [CSS Margin: 0 is not setting to 0](http://stackoverflow.com/questions/5387576/css-margin-0-is-not-setting-to-0) – Fundhor Oct 15 '15 at 16:02
-
Yep, paste your code, probably with a screenshot of the calculated css styles or box model or something from the chrome / firefox / ie debugger – cedd Oct 15 '15 at 16:04
2 Answers
1
Add this at the top of your stylesheet:
body {
margin:0px;
padding:0px;
}
the body has some default padding
and margin
setting that to 0 will make the elements stick to the edges

Antonio Smoljan
- 2,187
- 1
- 12
- 11
0
Tip: you can always check with a element inspector
If you press f12
you can see it's element inspector. The gray parts of the inspector shows you which default styles are enabled.
The body always has a margin
of 8px
by default. To disable it just use:
body{
margin: 0px;
}

Tom Groot
- 1,160
- 1
- 9
- 26