我试图添加一个英雄形象到我的网站。我已经准备好图像,并在我想要的位置,但不能设置它作为背景图像的英雄div。我在用wampserver64。
我试过使用background属性速记,但使用了background-image、background-size标记等。
下面是我代码的相关部分:
<head>中的链接
<link rel="stylesheet" href="styles/12cols.css" type="text/css"media="screen">
<link rel="stylesheet" href="styles/styles.css" type="text/css"media="screen"><div class="hero">
<h1>Placeholder</h1>
</div>CSS:
.hero {
background-image: url("../assets/hero-image.png");
background-position: center;
background-size: 100% auto;
background-repeat: no-repeat;
}我的文件夹结构如下:
project
-assets
-fonts
font.ttf (etc)
-hero-image.png
-styles
-12cols.css
-styles.css
-index.php
-login.php
-signup.php除了get http://project/favicon.ico 404 (Not Found)之外,我没有收到任何错误消息
更新:尝试将其作为一个HTML进行测试,而没有使用wampserver,但仍然没有效果。
还添加了一个高度和宽度规范,使其看起来如下:
.hero {
background-image: url("../assets/hero-image.png");
background-position: center;
background-size: 100% auto;
background-repeat: no-repeat;
width: 100%;
height: 1200px;
}也帮不上忙。
发布于 2022-02-27 11:44:34
IMG和CSS是不可见的,因为它们位于同一个目录中。尝试删除资产。
background-image: url("../hero-image.png"); https://stackoverflow.com/questions/57696559
复制相似问题