首页 > 解决方案 > 为什么背景图像设置为空正文元素可见?

问题描述

If i would try to set a background image to empty div then the background image is not 
visible.
So my question is: Why background image set to empty body element is visible?
Code:
<!DOCTYPE html> 
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Site</title>
<style>
*
{     /*CSS Reset*/
margin: 0px;
padding: 0px;
}
body
{
border:2px solid yellowgreen; /*body element do not contain any element and i am 
                                setting background image to body element and apply 
                                additional styling by selecting body element through element 
                                selector.*/
background-image: url(images/backgroundimage.jpg);
background-repeat: no-repeat;
}
</style>
</head>
<body>
</body>
</html>

body 元素不包含任何元素,我将背景图像设置为 body 元素,并通过元素选择器选择 body 元素来应用其他样式。在上面的示例中,背景图像是可见的,并且正在移出 body 元素的框。为什么会这样?

标签: htmlcss

解决方案


推荐阅读