简体   繁体   中英

div Img background doesn't work in my CSS

So this is my CSS code:

#plaatje {
background-image: url('Plaatjes\slider_two_temp.jpg');
width: 100%;
height: 600px;
position: absolute;
top: 0px;
left: 0px;

}

And it won't work at all. I placed the picture in the same map as my HTML file.

your code looks fine do a couple of things!

First check whether the id #plaatje is referenced correctly? also check for the path of css and html file

second check the path for your image the path you give in css is relative to your css file you should enter the correct path! if you're not sure about that use absolute path eg background-image: url('http://localhost/Plaatjes/images/slider_two_temp.jpg'); but beware if you have a large application you might then need to change all the paths for live server!

the last thing you could do is to hit ctrl+f12 for inspect element there you can what actually is wrong with your code!

also check your console by hitting ctrl+f12 many times the issues is that we are not using the correct path for our files which results in File not found error

if none of above works share your html code , css code so we can have a look at it hope that helps!!!

try this i think

 #plaatje { background-image:url('http://investorplace.com/wp-content/uploads/2016/02/google-amazon-goog-amzn-stock-300x200.jpg'); } 

https://jsfiddle.net/karanmehta786/rd1yezc2/

What you can try is you can enclose your id details in a style tag and you can make id name to any tag like paragraph tag and after that all your code will be alright.

<style>
 #plaatje{
    background-image: url('Plaatjes/slider_two_temp.jpg');
    width: 100%;
    height: 600px;
    position: absolute;
    top: 0px;
    left: 0px;
    }
</style>
    <p id="plaatje"></p>

If you want to try this by

 <div id="plaatje"></div>

it will also work fine for div tag

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