Hi everyone , I Am Designing a Web Template in Dreamweaver, and am having trouble with a gap (see attachment)

Here is the source code for the page (including CSS)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webtemplate</title><style type="text/css">
<!--
body {
    background-image: url(gradient-background.png);
}
.header {
    background-image: url(header.png);
    background-repeat: no-repeat;
    background-position: center top;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}
.pagecontents {
    font-family: "Segoe UI Light", "Segoe UI", "Ubuntu Beta";
    font-size: 12px;
    background-image: url(bg.png);
    background-position: center top;
    text-align: center;
    vertical-align: top;
    background-repeat: repeat-y;
    color: #FFF;
}
-->
</style></head>

<body>
<div class="header">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</div>
<div class="pagecontents">WHY DOES IT DO THIS ????</div>
</html>

any thanks would be much appreciated

Dani AI

Generated

Most likely causes: browser default margins on body/p elements, the three empty paragraphs inside the header used to create height, a stray transparent/white area in the header image, or unbalanced/mis‑nested tags changing how margins collapse. ’s markup uses blank <p>s to force header height; that creates margins and can collapse against neighboring blocks. ’s alternate structure (moving .pagecontents inside .header) changes containment and will change whether that gap appears — that’s why one version may look “fixed” without addressing the real problem.

Quick checklist to diagnose and fix

  • Inspect the gap with browser DevTools (select element, look at computed box model) to see which element’s margin or padding creates the space.
  • Remove empty paragraphs and control header height in CSS instead of using &nbsp; lines.
  • Reset user-agent spacing: set html/body margins to zero and remove paragraph margins where appropriate.
  • If margin collapse is involved, add a small padding, border, or overflow:auto/overflow:hidden to the parent to stop the child margin from sticking out.
  • Open the header image in an editor and crop any extra transparent or white pixels at the bottom.

Example CSS snippets to try (adjust height to match your header image):

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

.header {
  height: /* set to your header image height, e.g. 120px */;
  overflow: auto; /* prevents margin collapse from child <p> elements */
}

.header p { margin: 0; padding: 0; }

.pagecontents { margin-top: 0; }

Also ensure your HTML tags are properly balanced (close body/divs). Using a simple height/padding approach and removing empty <p> elements will make the layout predictable and eliminate the unexplained gap.

Recommended Answers

All 2 Replies

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webtemplate</title><style type="text/css">
<!--
body {
    background-image: url(gradient-background.png);
}
.header {
    background-image: url(header.png);
    background-repeat: no-repeat;
    background-position: center top;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}
.pagecontents {
    font-family: "Segoe UI Light", "Segoe UI", "Ubuntu Beta";
    font-size: 12px;
    background-image: url(bg.png);
    background-position: center top;
    text-align: center;
    vertical-align: top;
    background-repeat: repeat-y;
    color: #FFF;
}
-->
</style></head>

<body>
<div class="header">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
<div class="pagecontents">WHY DOES IT DO THIS ????</div>
</div>

</html>

thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.