我一直在尝试创建一个网站有一些麻烦。我的目标是创建一个名为“标题”的div,其中包含跨越页面顶部的背景图片。但是,当我将其编码为(就我的知识而言,它应该被编码)我只剩下一个空白页面。如何在div中显示图像?
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<link rel="stylesheet" type="text/css" href="mycss.css">
</head>
<body>
<div id="header"></div>
</body>
</html>
而且我的CSS
#header{
background-image: url("header.jpg");
50% 0 repeat;
background-size: cover;
}
你把这些值像'背景position'或'背景size'和'背景repeat'的属性。 – cocoa
尝试设置'display:block;宽度:100%;位置:相对; height:90px;'#header div'' 高度和宽度,因为'#header div'内没有内容。如果没有内容,如果未设置高度和宽度,则不会展开,并且您的背景不会显示。 – ghaschel