简体   繁体   English

HTML和CSS-不会显示background-image:url

[英]HTML & CSS - background-image:url not showing

Here is the html, for example: 这是html,例如:

<td class=topleft width=10 height=10></td>

Here is the CSS: 这是CSS:

td.topleft{
    border:0px;
    width: 100px;
    background-image: url(images/topleft.png);
    background-repeat:no-repeat;

}

the directory structure (starting with a folder on my desktop called site) 目录结构(从我桌面上的名为site的文件夹开始)

site.html site.html

styles.css styles.css

/images/topleft.png /images/topleft.png

Note: styles are being populated from the css file otherwise. 注意:否则将从CSS文件填充样式。

I have tried an absolute path with file: 我尝试了文件的绝对路径:

  background-image:url(file:///C:/Users/user/Desktop/site/images/topleft.png);

If I put that url in my browser directly, the image is reachable and appears. 如果我将该网址直接放在浏览器中,则该图片可以访问并显示。

Try using this HTML: 尝试使用以下HTML:

<td class="topleft">&nbsp;</td> <!-- TD not empty, inserting blank space -->

and this CSS: 和这个CSS:

td.topleft
{
    border: 0px;
    width: 100px;
    height: 100px;
    background-image: url(images/topleft.png);
    background-repeat: no-repeat;
}

verify that the image file name is lower-case, even in the extension. 验证图像文件名是否小写,即使在扩展名中也是如此。 Verify that the images folder is lower-cased too. 验证images文件夹也是小写的。 Does it work? 它行得通吗?

尝试这个 :

background-image: url(./images/topleft.png);

If your file links and file paths are correct it should work fine. 如果您的文件链接和文件路径正确,则应该可以正常工作。

example: http://jsfiddle.net/Vc8f6/ 例如: http//jsfiddle.net/Vc8f6/

To trouble shoot this you should try putting the CSS before the body tag using style tags to make sure the css works properly. 为了解决这个问题,您应该尝试使用样式标签将CSS放在body标签之前,以确保CSS可以正常工作。 If you still don't see the image check the file paths, spelling (case sensitive) and the extension (.png, .jpg, etc). 如果仍然看不到图像,请检查文件路径,拼写(区分大小写)和扩展名(.png,.jpg等)。

HTML 的HTML

<table>
<tr>
    <td class=topleft width=50 height=50>text goes here</td>
</tr>
</table>

CSS 的CSS

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM