html - 背景图片没有出现在div中?
问题描述
我有以下 div:
<div class="soundscapeImgDiv"> </div>
在 CSS 中,我尝试像这样设置它的背景:
.soundscapeImgDiv {
/* background-color: white; */
background-image:url('images/testImg.png') no-repeat;
background-size: 100%;
width: 280px;
height: 85%;
margin-left: 10px;
margin-top: 12px;
border-radius: 12px;
}
但是当我没有图像出现时。如果我只留下颜色,那么框就会出现。
如何解决此问题并使图像显示为背景?
更新:
我目前正在
GET file:///images/testImg.png net::ERR_FILE_NOT_FOUND
在终端。为了background-image:url('/images/testImg.png');
解决方案
使用background-repeat
物业
探索.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="css/explore.css">
</head>
<body>
<div class="soundscapeImgDiv"></div>
</body>
</html>
探索.css:
div.soundscapeImgDiv {
/* background-color: white; */
background-image: url("../images/testImg.png");
background-size: 100%;
background-repeat: no-repeat;
width: 280px;
height: 85%;
margin-left: 10px;
margin-top: 12px;
border-radius: 12px;
}
html, body {
height: 100%;
}
文件夹结构:
三重检查您的文件夹结构:
file: ///Users /用户名/Desktop/Portals.com/css/images/testImg.png
我相信您的目标是拥有这样的东西:
file:///Users/username/Desktop/Portals.com/images/testImg.png
请参阅此工作示例
推荐阅读
- r-markdown - “papaja”:标题页底部的“作者注释”标题
- php - 如何拆分 php dom 元素上的节点值
- python - matplotlib plot 会导致 sklearn 的 PCA.fit_transform 函数失败吗?
- android - Android:MVVM - RecyclerView 动态数据加载
- google-apps-script - 如何从Google工作表中存在上标的单元格中的句子中获取文本
- r - 用 ggrepel 和抖动点标记多面图
- c# - C# 数据注释未显示正确的显示名称
- flask - 如何使 WTForms 中的两个 FormField 中的至少一个成为必需的?
- java - 为最后一次出现的字符拆分字符串
- javascript - 如何在 Sequelize 中生成 12 位唯一 ID?