Hello,
I'm new to creating websites and I'm now following a tutorial to guide me. Unfortunatly, eventho I write exactly as the tutorial, my website's behavior isnt the same. It's pretty basic I guess.
I'd like to load a background image inside my CSS and apply it to my #home id. Here is my HTML structure :
<html>
<head>
</head>
<body>
<nav>
</nav>
<div id="home">
</div>
... (other divs)
</body>
</html>
And the corresponding CSS (path is OK) :
#home {
background-image: url("img/mountains.jpeg");
}
The weirdest part : when I try loading this image using background-image inside my "html, body {CSSHERE}", it loads perfectly
Do you have any idea ? i'd like to keep working on that but I'm stuck since hours
I've also tried all kind of path, relative and absolute. Weird thing is that other pictures (in the same folder, with the same privileges) are loading when it comes from <img>, but not when it comes from CSS (#home {background-image: url();}). My code is ok, it works for other people who tried it. I'm so confused !
- Posts
- 12936
- Registration date
- Monday June 3, 2013
- Status
- Moderator
- Last seen
- September 3, 2019
1342 -background-image: url('images/slides/background.jpg');
will look for images folder in the folder from which css is loaded. So if images are in another folder or out of the CSS folder tree you should use absolute path or relative to the root path (starting with /).
Is the CSS file in a different folder than the rest of the code? If so, then your path needs to be frmo the webserver root folder, not from the CSS folder.
I'm working on a local server (LAMP), my project folder is called elManel. If I understand your example, I've to precise "/elManel/img/myimage.jpeg" ? (/public-html is my server's root folder right ?).
I've tried it and other path (/Documents/public-html/elManel/img/myimage.jpeg) but none of them works to me unfortunalty. I've also tried puting my CSS into my "img" folder and changing my code, didnt work either.
I've been working a bit on Windows machine, i've done dozens of project (integration) and I never faced that kind of issues
- Posts
- 12936
- Registration date
- Monday June 3, 2013
- Status
- Moderator
- Last seen
- September 3, 2019
1342 -- Posts
- 12936
- Registration date
- Monday June 3, 2013
- Status
- Moderator
- Last seen
- September 3, 2019
1342 -Published directory:wwwroot
CSS folder location wwwroot\style
css file entry: BACKGROUND-IMAGE: url(\images\bcard.gif);
bcard.gif stored in wwwroot\images
See the relationship?