【问题标题】:HTML image no longer displaying after navigation integration导航集成后不再显示 HTML 图像
【发布时间】:2019-07-09 16:58:53
【问题描述】:

我正在建立一个响应式网站,在添加响应式导航后,分配给 div“.hero-image”的背景图像不再存在。 Google chrome 控制台出现错误“加载资源失败:服务器响应状态为 404(未找到)”

图片位于“img/Header.jpg”下

检查了我的新导航栏冲突代码,找不到问题。 仔细检查文件位置

CSS



.hero-image{
    background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url("img/Header.jpg");
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    position: relative;
}

.hero-text{
    text-align: left;
    position: absolute;
    margin-left: 20%;
    color: white;
    font-family: 'Roboto Mono', monospace;
}

*{
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
}

nav{
    display: flex;
    justify-content: space-around;
    align-items: center;
    min-height: 8vh;
    background-color: #343434;
    font-family: 'Roboto Mono', monospace;
}

#logo{
height: 100px;
}

.nav-links{
    display: flex;
    justify-content: space-around;
    width: 30%;
}
.nav-links li{
    list-style: none;
}
.nav-links a{
    color: white;
    text-decoration: none;
    letter-spacing: 3px;
    font-weight: bold;
}

.burger{
    display: none;
    cursor: pointer;
}

.burger div{
    width: 25px;
    height: 3px;
    background-color: white;
    margin: 5px;
    transition: all 0.3s ease;
}


@media screen and (max-width: 1024px){
    .nav-links{
        width: 60%;
    }
}

@media screen and (max-width: 768px){
    body{
        overflow-x: hidden; 
    }
    .nav-links{
        position: absolute;
        right: 0px;
        height: 100vh;
        top: 0vh;
        background-color: #3f3f3f;
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 80%;
        height: 100%;
        transform: translateX(100%);
        transition: transform 0.5s ease-in;
    }
    .nav-links li{
        opacity: 0;
    }
    .burger{
        display: block;
    }
}

.nav-active{
    transform: translateX(0%);
}

@keyframes navLinkFade{
    from{
        opacity: 0;
        transform: translateX(50px);
    }
    to{
        opacity: 1;
        transform: translateX(0px);
    }
}

.toggle .line1{
    transform: rotate(-45deg) translate(-5px,6px);
}
.toggle .line2{
    opacity: 0;
}
.toggle .line3{
    transform: rotate(+45deg) translate(-5px,-6px);
}

HTML

        <div class="hero-text">
        <h1>Ruan Kuypers</h1>
        <h2>Websites. Done. Right.</h2>
        <h3>A relighable business partner.</h3>
        </div>
    </div>

加载资源失败:服务器响应状态为 404(未找到)

【问题讨论】:

  • 你试过/img/Header.jpg吗?
  • @LeeTaylor 是的,我有,但仍然没有;(
  • @epascarello 我试过了,但还是不行。
  • 请编辑您的问题并包含您的 css、html 和图像文件夹/文件的层次结构

标签: javascript html css


【解决方案1】:

这取决于您的文件夹结构的外观以及您的 HTML 在目录或根文件夹中的位置。

如果是根文件夹试试:"./img/Header.jpg" 或在文件夹外试试"../img/Header.jpg"

【讨论】:

  • 您好,抱歉回复晚了,我试过了,还是不行。我有一个名为 img 的文件夹,其中包含图片“Header.jpg”,其余的位于名为 (“index.html, style.css, app.js”) 的根文件夹中
  • @Vexagon 没问题!您使用的是 Mamp 之类的网络浏览器吗?
  • @Vexagon "/img/Header.jpg" 尝试另一张图片将其添加到图片中看看是否有效。
  • 感谢您的宝贵时间,我设法找到了问题,css中的div分类设置为absolute。将其更改为相对并出现。 ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多