简体   繁体   中英

Background image not showing in ASP.NET Core

I am trying to add a background image to my ASP.NET Core application, but it's not showing.

Even a normal is not showing.

<div class="landing">
    <div class="text-center">
        <h2> app</h2>
        <h4>blah </h4>
        <button class="btn-success">See what we have</button>
    </div>
</div>
<style>
    .landing {
        background-image: url(..\..\wwwroot\images\bkimage.jpg);
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-size: cover;
        height: auto;
    }
</style>

I'll assume the snippet above is from an MVC view. When you're using the wwwroot folder, that represents the static content root against which other things can reference (unless you've explicitly changed that). So, the 'wwwroot/images/bkimage.jpg' would just be the root-relative path '/images/bkimage.jpg' off that.

Try the following:

background-image: url('/images/bkimage.jpg'); 

Height attribute must be quantified. For example: height:400px .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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