html - CSS 背景图片未加载

标签 html css image background

我已经学习了所有的教程,它们都说了。我在我的 css 样式表中指定了 body 内的背景,但页面只显示空白的白色背景。图像与 .html 和 .css 页面位于同一目录中。教程是这样说的

<body background="image.jpeg">

已弃用,所以我在 css 中使用

body {background: url('image.jpeg');}

没有成功。 这是整个 CSS 样式表:

body 
{
background-image: url('nickcage.jpg');
padding-left: 11em;
padding-right: 20em;
font-family:
Georgia, "Times New Roman",
Times, serif; 
color: red;        
}

最佳答案

首先,向那些引述说再见吧:

background-image: url(nickcage.jpg); // No quotes around the file name

接下来,如果您的 html、css 和图像都在同一个目录中,那么删除引号应该可以解决问题。 但是,如果您的 css 或图像位于您的 html 所在位置的子目录中,您将需要确保正确路径到图像:

background-image: url(../images/nickcage.jpg); // css and image live in subdorectories

background-image: url(images/nickcage.jpg); // css lives with html but images is a subdirectory

希望对您有所帮助。

关于html - CSS 背景图片未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21374534/

相关文章:

javascript - jquery用jsp文件内容替换div内容

javascript - 文本淡出/阅读更多链接

在服务器上找不到 CSS 样式表?

html - 固定 header 上的 z-index 不起作用

html - 简单的页脚问题

javascript - 从网络创建全屏幻灯片的最佳工具

javascript - 如何在 iFrame 上显示图像?

javascript - jQuery 浏览器高度不准确

javascript - JQuery数据表土耳其语字符搜索问题

java - Windows 8 上 Java 8 Update 45 中的可能错误