在CSS中有关`background-image`的问题。

huangapple go评论60阅读模式
英文:

Issue with background-image: in css

问题

我试图将一张图片添加到我的网站背景中,但似乎没有生效。

HTML

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" href="styles.css">
</head>
<body>
	<div class="nav">
		<h4 class="nav-text">USER</h4>
	</div>
</body>
</html>

CSS

body {
    background-color: black;
    background-image: url("background.png");
}

.nav {
    background-color: black;
    opacity: 50%;
    height: 45px;
}

.nav-text {
    opacity: 100%;
    color: white;
    float: right;
    margin-right: 25px;
    margin-top: 12px;
}

我应该更改什么以使其显示图片而不是什么都不做?

英文:

I'm trying to add an image to the background of my website, and it isn't seeming to work. (Code is lacking because I am trying to get this to work first.

HTML

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
	&lt;meta charset=&quot;UTF-8&quot;&gt;
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
	&lt;title&gt;Document&lt;/title&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;/&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;div class=&quot;nav&quot;&gt;
		&lt;h4 class=&quot;nav-text&quot;&gt;USER&lt;/h4&gt;
	&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

CSS

body {
    background-color:black;
    background-image: url(&quot;background.png&quot;)
}

.nav {
    background-color: black;
    opacity: 50%;
    height: 45px;
}

.nav-text {
    opacity: 100%;
    color: white;
    float: right;
    margin-right: 25px;
    margin-top: 12px;
}

What am I supposed to change to make it display the image rather than do nothing?

答案1

得分: 0

原来是浏览器缓存的问题,按下 CTRL + F5 解决了这个问题。

英文:

Turns out it was an issue with my browsers cache, pressing CTRL + F5 fixed the issue.

huangapple
  • 本文由 发表于 2023年7月20日 10:41:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定