[英]HTML and CSS Background-image is not showing up
我已经仔细检查了我的 URL 和文件名,但我似乎无法显示图像。 为什么会这样? 这是我的代码 注意
在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,
这是该部分的 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;
}
你的 CSS 看起来不错。
您的问题在于 URL 本身。 你可能的意思是:
background-image: url(../images/background.gif);
由于您使用的是相对路径并且样式表位于“ stylesheet/ ”目录中,因此您的代码让浏览器查找“ stylesheet/images/background.gif ”,因为它是相对于样式表而不是文档。
在您的 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;
}
如果这不起作用,请尝试设置宽度和高度以及显示块。
将高度和宽度提到宽度,以便背景图像出现。
检查以确保您在 'url' 函数中使用的路径是正确的,然后使用 'background-size' 属性来减小图像的大小,因为过大的图像总是有这种副作用,并且可能使用 'background-position :cover' 在其骗局中传播图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.