简体   繁体   English

出现背景图片未显示的问题

[英]having issue with background-image not showing

My background-image isn't showing and its driving me crazy as I know it's something easy. 我的背景图片没有显示,它使我发疯,因为我知道这很容易。

The div class below is where I'm trying to get the background to show. 下面的div类是我试图显示背景的地方。

.sun-face{
    background-image: url("./images/Sun_face.svg");
}


<div class="sun-face"></div>

My file directory is structured like so. 我的文件目录的结构如下。

ROOT
    -css
    -fonts
    -images
    -js
    index.html
    navbar.html
    signin.html

use this css 使用这个CSS

.sun-face{
background-image: url("../images/Sun_face.svg");
height:500px;
}

I've had this problem before and it was caused by a mime-type server issue. 我以前遇到过此问题,它是由mime型服务器问题引起的。 Basically the server wasn't configured to serve .svg files. 基本上,服务器未配置为提供.svg文件。 Check your console, generally if this is the case you'll see something like 'Resource interpreted as image but transferred with MIME type...'. 检查控制台,通常情况下,您会看到类似“将资源解释为图像,但以MIME类型传输的信息...”之类的信息。 This can be fixed by adding a few lines the .htaccess file on your server. 可以通过在服务器上添加几行.htaccess文件来解决此问题。 See this css-tricks article . 请参阅此CSS技巧文章

So I added it in an inline style sheet, 所以我将其添加到内联样式表中

this works, however I want it in my css file 这可行,但是我想要在我的css文件中

 <style>
    .sun-face{
        background-image: url("./images/Sun_face.svg");
        height:500px;
        width:100%:
    }
    </style>


<link href="./css/custom.css" rel="stylesheet">

I put it in ^^ doesn't work? 我把它放在^^不起作用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM