HTML 和 CSS 背景图像未显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8839374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML and CSS Background-image is not showing up
提问by user962206
I already double checked my URL, and the name of the files, but I can't seem to get the image showing up. why is it like that? here's my code Take note the
我已经仔细检查了我的 URL 和文件名,但我似乎无法显示图像。为什么会这样?这是我的代码 注意
is inside the body tags, I didn't add the full code, I only added the head and the specific problem.
在body标签里面,我没有添加完整的代码,我只添加了头部和具体问题。
<html>
<head>
<title>Head First Lounge.</title>
<link type = "text/css" rel = "stylesheet" href = "stylesheet/style.css" media = "screen"/>
</head>
<p class = "guarantee">
our guest, with an exceptional experience every time you visit.
Whether you're just stopping by to check in on email over an
elixir, or are here for an out-of-the-ordinary dinner, you'll
find our knowledgeable service staff pay attention to every detail.
If you're not fully satisfied, have a Blueberry Bliss Elixir on us.
</p> Our guarantee: at the lounge, we're committed to providing you,
And here's the CSS rule for that part
这是该部分的 CSS 规则
.guarantee{
background-image: url(images/background.gif);
font-family: "Geogia", "Times New Roman", Times, serif;
border-color: black;
border-width: 1px;
border-style: solid;
background-color: #a7cece;
padding: 25px;
margin: 30px;
line-height: 1.9em;
font-style: italic;
color: #444;
}
回答by rgthree
Your CSS looks fine.
你的 CSS 看起来不错。
Your problem lies in the URL itself. You probably mean:
您的问题在于 URL 本身。你可能的意思是:
background-image: url(../images/background.gif);
Since you're using relative paths and your stylesheet is in "stylesheet/" directory, your code has the browser looking for "stylesheet/images/background.gif" as it's relative to the stylesheet, not the document.
由于您使用的是相对路径并且样式表位于“ stylesheet/”目录中,因此您的代码让浏览器查找“ stylesheet/images/background.gif”,因为它是相对于样式表而不是文档。
回答by Kris Hollenbeck
Try ../ before your URL. Also if you inspect the background-property in firebug you should be able to tell if is actually finding the URL.
在您的 URL 之前尝试 ../ 。此外,如果您检查 firebug 中的背景属性,您应该能够判断是否确实找到了 URL。
.guarantee{
background-image: url(../images/background.gif);
font-family: "Geogia", "Times New Roman", Times, serif;
border-color: black;
border-width: 1px;
border-style: solid;
background-color: #a7cece;
}
If that deosn't work try setting a width and height and display block.
如果那个 deos 不起作用,请尝试设置宽度和高度以及显示块。
回答by MAK
mention the height and width to the width so that the background image will appear.
将高度和宽度提到宽度,以便背景图像出现。
回答by Monday A Victor
Check to make sure the path you are using in the 'url' function is correct then use 'background-size' property to reduce the size of the image since over-sized images always has that side effect and the probably use 'background-position:cover' to spread the image in its con
检查以确保您在 'url' 函数中使用的路径是正确的,然后使用 'background-size' 属性来减小图像的大小,因为过大的图像总是有这种副作用,并且可能使用 'background-position :cover' 在其骗局中传播图像