.net Core 3.1 error 404 adding background-image in css

匆匆过客 提交于 2021-01-29 14:30:27

问题


Imagem Erro

I am getting error 404 (in console) when adding background-image: url("/wwwroot/images/bg-01.jpg");

What i did was to remake the login page with a template, and it's all working. But cant add image to background.

I have a template with pure css and html and js in notepad that is working.only when passing to .net core. the image is with error. In view i am not using _Layout The path is correct since i tested touse in a img tag with href:/wwwroot/images/bg-01.jpg and it works fine. I also tried to use an correct url image from web and same error Anyone can help.?


回答1:


You need to use like url('/images/bg-01.jpg'),here is a demo:

wwwroot:

view:

<div id="div1">
        <div id="div2">
            Peppa
        </div>
    </div>
 <style>
     #div1 {
         background-image: url('/images/Peppa.jpg');
         width: 279px;
         height: 181px;
     }
     #div2 {
         background-image: url('/images/green.PNG');
         width: 100px;
         height: 50px;
     }
 </style>   

result:



来源:https://stackoverflow.com/questions/64416647/net-core-3-1-error-404-adding-background-image-in-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!