I have about 20 pixels of white space at the top of my page. I have inspected every element and nothing has padding or margin in this area. When I inspect the body element it does NOT include this space. When I inspect the html element is does include this space. Also if I delete
<!DOCTYPE html>
the white space goes away.
Here is my main layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@RenderSection("Css", false)
</head>
<body>
@RenderSection("JavaScript", false)
</body>
</html>
Aside from the css reset, I also added the following to the css of my
div
container and that fixed it.I Just put CSS in my
<div>
now working in codeAdd a css reset to the top of your website style sheet, different browsers render some default margin and padding and perhaps external style sheets do something you are not aware of too, a css reset will just initialize a fresh palette so to speak:
UPDATE: Use the Universal Selector Instead: @Frank mentioned that you can use the Universal Selector:
*
instead of listing all the elements, and this selector looks like it is cross browser compatible in all major browsers:Check for any webkit styles being applied to elements like ul, h4 etc. For me it was margin-before and after causing this.
Try this
Old question, but I just ran into this. Sometimes your files are UTF-8 with a BOM at the start, and your template engine doesn't like that. So when you include your template, you get another (invisible) BOM inserted into your page...
This causes a gap at the start of your page, where the browser renders the BOM, but it looks invisible to you (and in the inspector, just shows up as whitespace/quotes.
Save your template files as UTF-8 without BOM, or change your template engine to correctly handle UTF8/BOM documents.