user3163495
user3163495

Reputation: 3672

HTML - Which element has the page's scrollbar: <BODY> or <HTML>?

In a simple, compliant HTML document, where the content in the <BODY> element is of greater height than the browser's viewport, a vertical scrollbar will appear on the right (unless the scrollbar is disabled, of course).

When this happens, which element is the scrollbar attached to: <BODY> or <HTML>?

Upvotes: 1

Views: 358

Answers (4)

Nawaf Alharby
Nawaf Alharby

Reputation: 11

try Adding:

   * {
outline: 1px solid green;
}

Then when you scroll down you can see tall box (big one) after you right click on it to inspect element Then you should see all the information you need.

Upvotes: 1

Charles Stover
Charles Stover

Reputation: 1148

By default, at least in Chrome, <html>. You can test this by scrolling down on this page and comparing document.body.scrollTop to document.getElementsByTagName('html').item(0).scrollTop.

There is nothing requiring that you maintain this choice, and you are able to override this default behavior using CSS.

Upvotes: 1

MajiD
MajiD

Reputation: 2585

as David Murdoch described Here this is the best way to know

function getScrollingElement() {
  var d = document;
  return d.documentElement.scrollHeight > d.body.scrollHeight &&
    d.compatMode.indexOf('CSS1') == 0 ?
    d.documentElement :
    d.body;
}

Upvotes: 1

Chayim Friedman
Chayim Friedman

Reputation: 71450

If you're asking to know how element attach the CSS property overflow, this doesn't matter. You can attach it to <html> or to <body>, as you prefer.

Upvotes: 1

Related Questions