我已经学习了所有的教程,它们都说了。我在我的 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/