简体   繁体   中英

Image works fine as a HTML <img> but not on CSS background-image What I'm I missing?

I'm somewhat new to web development (self learning) and I just can't seem to get over the hump of learning how to add background images on CSS.

I added a image on HTML and it shows up fine on the web browser, but when I try to add the same image as a Background Image it's not working. I'm sure I'm missing something simple but so far I cant figure it out. Here is the code

This is my HTML img code that works perfectly fine

<div class="pic"
<img src="C:\Users\omar\Pictures/applelogoretro.jpg.jpg" atl="happy"
style="width:85%; height:75%;"/>
</div>

Background image HTML

<div class="backpic">
<p>This is the TEXT on my BackGround image</p>
</div>

CSS

.backpic{
background-image: url"C:\Users\omar\Pictures/applelogoretro.jpg.jpg";
}

Why does the image work fine as a regular image, but not as a background image. The more detail your answer the more it will help me, thanks in advance to all!

可以尝试检查语法,看看是否可以呢?

background-image: url("pathtoyourimage.jpg");

Url in css should be inside parenthesis:

So this line background-image: url"C:\\Users\\omar\\Pictures/applelogoretro.jpg.jpg";

Should be background-image: url("C:\\Users\\omar\\Pictures/applelogoretro.jpg.jpg");

As @Raptor and @YAHsaves pointed out, you should use relative paths

Try checking the syntax error(>), see if it will do this

.pic{ background-image: url(ggg.jpg);  
  background-repeat: no-repeat;
 }

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