Exploring a particular style rule:
body {
font-family: Georgia, serif;
font-size: 100%;
line-height: 175%;
margin: 0 15% 0;
background-color: #d2dc9d;
background-clip: content-box;
}
During testing of a page utilizing this rule, the background-clip
property did not seem to have any impact. The background color extended beyond the content box, over the margin, and all the way to the edge of the screen.
Seeking clarification in the specification:
https://www.w3.org/TR/css-backgrounds-3/#the-background-clip
It was noted that the root element has a distinct background painting area, rendering the
background-clip
property ineffective when applied to it.
Additionally, there was reference to another relevant discussion on SO:
Why does styling the background of the body element affect the entire screen?
In CSS, values do not propagate upwards; elements do not pass values to their ancestors. However, background styles assigned to the body element can transmit to the html element, which serves as the document's root and defines its canvas.
Could it be that the background color I apply is being transferred from the <body>
element to the root <html>
element? Therefore, clipping the background to the content box of <body>
may not produce visible results due to the obscuring effect caused by the color filling the canvas of <html>
?
If so, is there a method for me to visually clip to the content box of <body>
? Would inserting a <div>
between <body>
and the body content and styling it provide a potential solution?