Background image doesn't show when defined in

2019-06-16 04:03发布

I am very new to css so this maybe a simple answer. I have 2 scenarios and 1 works the other doesn't. I hope someone can help me out.

WORKS:

<head>
<style type="text/css"> 
body { 
    background-image:url('views/default/images/home.jpg');
;}
</style>
</head>

DOESN'T WORK:

<head>
<link rel="stylesheet" type="text/css" href="views/default/home_style.css" />
</head>

In home_style.css>

body{ 
    background-image:url('views/default/images/home.jpg');
    margin-top: 0px !important; 
    padding-top: 0px !important; 
}

2条回答
手持菜刀,她持情操
2楼-- · 2019-06-16 04:19

It looks like your CSS file is in the views/default/ folder, while the image is in the views/default/images/ folder.

Define image paths in your CSS relative to the CSS file, not the HTML file that displays everything:

background-image:url('images/home.jpg');
查看更多
走好不送
3楼-- · 2019-06-16 04:37

In my case:

I had a CSS folder. So, inside my CSS folder I had my style.css so I was typing inside my style.css the following:

background: url('img/mybgimg.jpg')

instead of

background: url('../img/mybgimg.jpg')

...I hope this can help to anyone who is having the same issue.

查看更多
登录 后发表回答