简体   繁体   English

div Img背景在CSS中不起作用

[英]div Img background doesn't work in my CSS

So this is my CSS code: 这是我的CSS代码:

#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. 我将图片放置在与HTML文件相同的地图中。

your code looks fine do a couple of things! 您的代码看起来不错,可以做几件事!

First check whether the id #plaatje is referenced correctly? 首先检查ID #plaatje是否正确引用? also check for the path of css and html file 还要检查css和html文件的路径

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! 第二步检查图像的路径,您在css中指定的路径是相对于css文件的路径,您应该输入正确的路径! if you're not sure about that use absolute path eg background-image: url('http://localhost/Plaatjes/images/slider_two_temp.jpg'); 如果您不确定使用绝对路径,例如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! 您可以做的最后一件事是按ctrl + f12来检查元素,在那里您可以发现代码实际上有什么问题!

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 还可以通过多次按ctrl + f12来检查控制台,问题是我们没有为文件使用正确的路径,这导致文件未找到错误

if none of above works share your html code , css code so we can have a look at it hope that helps!!! 如果以上任何一个作品都没有共享您的html代码,css代码,那么我们可以看一下希望对您有所帮助!!!

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/ 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. 您可以尝试的是将ID详细信息括在样式标签中,并可以将ID名称命名为任何标签(如段落标签),然后所有代码都可以。

<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 对于div标签也可以正常工作

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

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