Search code examples
htmlcssbackground-imagelocal

Local background image doesn't show up, but if I replace it with one on the web it does work


Here is my HTML and CSS https://codepen.io/anon/pen/YBmLJR

header{
    background-image: url(slike\header\header-ozadje.png);
    position: fixed;
    width: 100%;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #E2B654;
}
#top-logo img{
    box-sizing: border-box;
    max-width: 100%; height: auto;
    padding: 5%;
}
nav{
    display: flex;
    justify-content: flex-end;
    flex: none;
    margin-right: 2%;
}
.nav-text{
    margin: 15px;
    flex: none;
}
.nav-text a{
    text-decoration: none;
    font: bold 16px/28px 'Open Sans', sans-serif;
    color: antiquewhite;
}
.nav-text a:hover{
    color: #DFB76B;
}
<header>
        <div id="top-logo">
            <img src="slike\logo\astroplanet-logo.png"> 
        </div>      
        <nav>
            <div class="nav-text"><a href="#">DOMOV</a></div>
            <div class="nav-text"><a href="#">DOMOV</a></div>
            <div class="nav-text"><a href="#">DOMOV</a></div>
            <div class="nav-text"><a href="#">DOMOV</a></div>
            <div class="nav-text"><a href="#">DOMOV</a></div>
        </nav>
    </header>

The background image linking to my local folder (I copied the relative path in VSC, so it should be correct) in my header doesn't show up, but it does if I replace it with a URL that is on the web.

If you run the code there is also the logo, but that should have the broken link image.

Thank you for your help!


Solution

  • Before location you have to put slash you should replace your image location with this background-image: url(/slike/header/header-ozadje.png);