我这里有我的 html 和 css 代码。我似乎没有理解为什么我的图像无法加载或显示的问题。我试过它们在 firefox 和 chrome 上都加载。
我的问题不在 jsfiddle 上。
这是我的文件夹结构:
- 本地主机/网站/img
- 本地主机/网站/css
- 本地主机/网站
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="description" />
<meta name="author" content="author" />
<link href="css/index.css" rel="stylesheet" type="text/css" />
<title>Title</title>
</head>
<body>
<div id="container">
<div id="sidebar">
<div id="logo"></div>
</div>
</div>
</body>
</html>
@charset "utf-8";
/* Body */
#body {
font-family: Arial, Helvetica, sans-serif;
margin: 0px;
padding: 0px;
background: #ccc;
}
/* Container */
#container {
width: 100%;
background: #000;
}
/* Sidebar */
#sidebar {
background: url(../img/sidebar.png) repeat-y;
width: 40%;
float: left;
position: fixed;
}
/* Logo */
#logo {
background-image: url(../img/logo.png);
}
最佳答案
您有两张图片,它们被添加为 div 的背景图片,但这些 div 没有布局,因为侧边栏缺少高度以及 Logo 高度和宽度。这意味着他们根本不会出现。给他们高度/宽度来修复它。
如果不是,图片的路径是错误的。
关于html - 背景图片不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7091925/