开发者

Body background-color strange behavior

Suppose we have a simple HTML page:

&开发者_StackOverflowlt;html>
<body style="background-color: red; width: 100px; height: 100px; border: 1px solid black">
</body>
</html>

Browsers (except for IE) would render it like this:

Body background-color strange behavior

 

The question is why does the area outside the body element (which itself is 100px wide and 100px high) have a red background?


'cause body is your entire document. you can't limit it to 100x100px.

you may use a div to create your box :

<html>
<body>

<div style="background-color: red; width: 100px; height: 100px; border: 1px solid black"></div>

</body>
</html>


I can only assume because you havent specified a background color for your 100x100px square? (only a guess without seeing more of your CSS code)


Because the bodys background is the one that the whole page gets assigned, too. What would you expect? A white background that you can't get rid of?


This example can be made to work, but you will need to apply styles to both the HTML tag and the BODY tag, like so:

<html style="background-color:white;">
<head></head>
<body style="background-color: red; width: 100px; height: 100px; border: 1px solid black">
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜