HTML&;CSS-背景图像:url未显示

HTML&;CSS-背景图像:url未显示,html,css,Html,Css,以下是html,例如: <td class=topleft width=10 height=10></td> 目录结构(从我桌面上名为site的文件夹开始) site.html styles.css /图像/topleft.png 注意:样式是从css文件填充的,否则 我已尝试使用文件的绝对路径: background-image:url(file:///C:/Users/user/Desktop/site/images/topleft.png); 如果我将该ur

以下是html,例如:

<td class=topleft width=10 height=10></td>
目录结构(从我桌面上名为site的文件夹开始)

site.html

styles.css

/图像/topleft.png

注意:样式是从css文件填充的,否则

我已尝试使用文件的绝对路径:

  background-image:url(file:///C:/Users/user/Desktop/site/images/topleft.png);
如果我将该url直接放在浏览器中,则图像可以访问并显示。

尝试使用以下HTML:

<td class="topleft">&nbsp;</td> <!-- TD not empty, inserting blank space -->
验证图像文件名是否为小写,即使扩展名也是如此。确认
图像
文件夹的大小写也较低。它有用吗?

试试这个:


背景图像:url(./images/topleft.png)

如果您的文件链接和文件路径正确,它应该可以正常工作

例如:

要解决这个问题,您应该尝试使用样式标记将CSS放在body标记之前,以确保CSS正常工作。如果仍然看不到图像,请检查文件路径、拼写(区分大小写)和扩展名(.png、.jpg等)

HTML


你能显示
site.html
相对于
images/
的目录结构吗?你可以使用浏览器的
Inspect元素来获取真实图像的url。我建议:1)将“images”文件夹移到.css所在的位置,而不是放在计算机的根目录或桌面上。2) 移除td width=10,height=10,看看这是否会影响显示(10px 10px)。因此,您的元素根本不会显示。尝试在
@user1166981之间放置一些文本。您使用chrome的
检查元素
功能获取图像的url,然后与绝对路径进行比较以获取请求!
<td class="topleft">&nbsp;</td> <!-- TD not empty, inserting blank space -->
td.topleft
{
    border: 0px;
    width: 100px;
    height: 100px;
    background-image: url(images/topleft.png);
    background-repeat: no-repeat;
}
<table>
<tr>
    <td class=topleft width=50 height=50>text goes here</td>
</tr>
</table>
td.topleft{
border:0px;
width: 500px;
height: 150px;
background-image: url(http://www.smiley-faces.org/wallpaper/smiley-face-wallpaper-widescreen-001.jpg);
background-repeat:no-repeat;
}