zrooda
zrooda

Reputation: 3683

Body background in Chrome disregarding position of body

When you move the body element on a particular page in Chrome (testing v23) using position: relative; top: 100px; as example, the background is still applied to the whole viewport.

Is this a Chrome bug or could anyone explain the behavior / supply a flexible solution?

Upvotes: 1

Views: 101

Answers (1)

BoltClock
BoltClock

Reputation: 724402

This is actually expected behavior for all browsers: while the body element is indeed being offset 100 pixels from the top, the background itself is being seamlessly propagated to the viewport as described in the first part of this answer. It's probably a holdover from the era of HTML presentational attributes, where setting background attributes on body allowed the background to be propagated to the viewport, giving an appearance of applying a background to the whole page.

If you want to restrict the background to only the body element, simply give html a background color that is anything other than transparent, or give it a background image. The viewport will then use the background of html instead.

Upvotes: 1

Related Questions