On this page:

it seems like the gray background object is larger than the screen - i.e. scroll bars appear even though the content is not long enough to warrant them. I have the following properties:

body
{
height: 100%;
}

html
{
height: 100%;
}

Shouldn't it be exactly the right size and therefore not need scrollbars?

Thanks,

David

Dani AI

Generated

The scrollbar is almost certainly coming from layout rules that make the page a hair taller than the viewport. was right to flag a forced overflow rule; also nailed two big contributors: an html element sized larger than the viewport and the body being shifted down. 's reminder that “100%” is about the element’s box (not the screen) explains why small offsets and margins add up to overflow.

Quick diagnosis steps:

  • Inspect computed sizes in DevTools (html/body computed height, scrollHeight vs clientHeight) and temporarily toggle suspected rules (overflow, html height, body offset).
  • Look for cumulative space: a relative top shift still reserves the original flow space, default paragraph margins and extra margins on inner boxes add to the total, and an absolutely positioned footer can complicate things.

Practical fixes (apply one at a time and retest):

  • Remove any rule that forces scrollbars (do not use overflow:scroll on the root).
  • Avoid moving the body with relative top. Instead create a page wrapper and use margin or padding to reveal the html background above the blue body. That avoids leaving "reserved" space that increases document height.
  • Reset default element margins (or normalize them) so the logo paragraph or first child doesn't add unexpected vertical space.
  • Replace an absolutely positioned footer with a modern layout so it does not force extra height — for example, use a column flex layout to keep the footer at the bottom without absolute positioning:
/* .site wraps header, main, footer */
.site {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.site main { flex: 1; }

Checklist: ensure html height is not artificially >100%, remove forced overflow, replace top offsets with margin/padding on a wrapper, and check default element margins. These steps will remove the unwanted scrollbars while keeping the visual gaps you want.

Recommended Answers

All 8 Replies

You have overflow: scroll on your html tag? Thats whats causing the scroll bar.

I don't have that - it is commented:

html
{
height: 100%;
/*overflow: scroll;*/
}
body
{
height: 100%;
/*overflow: scroll;*/
}

html
{
height: 100%;
overflow: scroll;
}

.lightblue
{
  color:#169fcd;
}

p
{
  margin-top:0;
}

.title1
{
color: #0000BB;
font-size: 25pt; 
}
h2
{
font-size: 20pt; 
}

Thats what I see in your stylesheet.

right? Do you have a recent version?

  1. The height in your html rule is set to 101%.
  2. Your body element is positioned relatively and has a top style of 10%.
  3. Your div with a class of whitebox has a margin-top: 10px;
  4. You have a paragraph containing your logo. Paragraphs create a new line both before and after the paragraph element.

Regards, Arkinder

The height in your html rule is set to 101%.

I've been told that this may be a good idea so that the scrollbar is always displayed no matter how long the content is. However, my question still remains that this page should actually have nothing to scroll (though it still does).

Your body element is positioned relatively and has a top style of 10%.

This is because I want some gray (the html background-color) to show above the blue (the body background-color). Is this not how I would achieve this?

Your div with a class of whitebox has a margin-top: 10px;

This is because I want some blue (the body background-color) to show above the white (the whitebox background-color). Is this not how I would achieve this?

You have a paragraph containing your logo. Paragraphs create a new line both before and after the paragraph element.

Should I make it a div instead? Surely that is not what is causing the page to be about 10% taller than the screen, right?

100% height refers to the content, not the screen size.

I've been told that this may be a good idea so that the scrollbar is always displayed no matter how long the content is. However, my question still remains that this page should actually have nothing to scroll (though it still does).

This is an optional display technique which is basically useless. If the content extends past 100% of the browser window a scrollbar will appear on its own. If the inconsistency across pages bothers you, then use it.

This is because I want some gray (the html background-color) to show above the blue (the body background-color). Is this not how I would achieve this?

It pushes the body element and everything in your page, 10% from the top. You should use a division and probably margin instead.

This is because I want some blue (the body background-color) to show above the white (the whitebox background-color). Is this not how I would achieve this?

No, that's fine but in Firefox and Chrome it does nothing (on a Mac)

Should I make it a div instead? Surely that is not what is causing the page to be about 10% taller than the screen, right?

Right, but you do have another element being pushed exactly 10% from the top.

Things to keep in mind~

  1. Your footer is absolutely positioned. This removes it from the normal flow of the page. Also, there are better ways of positioning it at the bottom.
  2. Every browser has its own default margin and padding. You can "reset" this with a universal rule.
    * {
        margin: 0;
        padding: 0;
    }

    This sets the margin and padding for every element to 0.

  3. Make sure that you're familiar with the box model.

If you need better explanations, examples, etc. Feel free to ask.

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.