Multiple Folder Organising and Referencing CSS - css

OK so I am Trying To Organize a file directory for a website. It looks like this.
- My Blog Site
- HTML-CSS-DOCUMENTS
- CSS-MAIN.css
- BACKGROUND-IMAGES
- Background.png
But in the CSS document I cant seem to get it to use the image.
Here is the code I have been using
background-image:url("My Blog Site\BACKGROUND-IMAGES\Background.png");
Can someone please fix it or tell me what I'm doing wrong, thanks!

You need to go back in the path and get your image. something like this:
background-image: url('../BACKGROUND-IMAGES/Background.png');
Here ../ means going one step back in the path. And use / instead of \.

You would use in your CSS:
background-image: url('../BACKGROUND-IMAGES/Background.png');
You go back one directory using the ../ and then link from that directory.

This should work fine:
background:url('http://mywebsite.com/background-images/background.png');

Related

Can't find resource from css

I can't find solution to load image linked in css. Chrome inspector shows me message:
404 (not found)
and shows me this link: http://127.0.0.1:5500/components/css/img.png
even if I have in my css
background-image: url(../src/splash_1/img.png)
Could anyone please help me with appropriate linking... I can't find answer how to correctly link that image in that folder structure.
UPDATE:
Below in the second picture attached, I added print screen with real data from Chrome Inspector and code and the element. Maybe that will be more helpful. I want to link correctly
ccbackground.jpg
Thank you!
You just need to pass the path as a string in single quotes with the same path you tried first. The .. is needed to step one folder up from the css folder.
background-image: url('../src/splash_1/img.png');
Note: it can be that the path is cached locally on the client side, you may need to clear browser cache to make it work.
Eventually it turned out I had 2 pairs of the same css files in different location. One pair in correct location and the other in main folder. I was changing css files in editor located in main folder, but in index.html css files were linked to specified folder. So even I changed css it didn't reflect changes in index.html, because the changes were done in the same name css files but in other location. I wonder how it happened I had 2 pairs of css files in different location, this is something really unclear for me. Thank you All for your help and your time.
Try this
background-image: url('/src/splash_1/img.png');
Please try below code...
background-image: url('components/src/splash_1/img.png');

Changing Jumbotron Image

Setup:
Product -> src -> static -> ostatic [ contains two folders css and images ] -> images -> this contains all my images.
Using bootstrap and trying to add background-image: to jumbotron, having spent two hours now it's really bothering me. Within django I can just call {% static 'images/imagename.jpg' %}" and it'll work fine, but when trying to do i.e. background-image: url('images/imagename.jpg'); this will not work and I've tried many other combinations too, including reading a lot of stackoverflow questions on topic..none of the solutions have seemed to help me though =/
I think you need to make the path relative to the site root. Based on the structure you tell us:
background-image: url('/src/static/ostatic/images/imagename.jpg');
The leading / should start the path at the site root.
I had the same problem!
it looks like you can't use a local picture there and that it must be a link
I mean something like this:
background-image : url(https://image.freepik.com/free-photo/bight-orange-colored-light-bulb_23-2148182084.jpg);
not that specific link tho ^_^

External CSS images won't load

Good day.
My structure is like this:
/
index.html
style/
main.css
images/
test/
test.html
/style/main.css says something like this:
body {
background-image: url('/images/SomeImage.png');
background-color: #000;
}
/index.html has a link to this CSS file, but, as the title says, no image will load. But it's connected though, cause the background is actually black, so the rest of the style (but images) does work.
Also, if I write the same style internally into /index.html the background will load.
Also, I created /test/test.html which says nothing but
<img src="/images/SomeImage.png" />
and the image is displayed on that page.
So, obviously, for some reason my /style/main.css can't reach files, that any other file from any other location reaches. Why does this happen? There's clearly nothing wrong with the syntax. I'm lost.
add ../ to the beginning of /images so it read ../images/imagename.jpg
Here's what your code should be:
body {
background-image: url('../images/SomeImage.png');
background-color: #000;
}
Because your image is in another folder (thats a level up than your style sheet), you need to start with "../" for a level up folder in hierarchy relative to the style sheet. So you need a relative URL:
background-image: url('../images/SomeImage.png');
Try to copy webpage, css and example image in one folder temporarily. Then use only image name for url a see what happens. If it works, it will be the image path, if not something else.. possibly position.. is this complete css you are posting?
Initially, it looks like your code is fine.
So how do you know the image isn't loading? Look in your browser's developer tools to see if the image is loading, or returning an error, or not even being referenced. My guess here would be that it is loading, but not display because of something in your CSS.
if you are in /styles/style.css you need to add:
../ 2 levels back to get to the root folder.
So as Rokin answered :
background-image: url('../images/SomeImage.png');
is the way to do it.
To link your CSS within your index file use the following:
<link href="./style/style.css" rel='stylesheet' type='text/css'>
./ 1 level back within the index.html to reach the root folder.
In addition your problem might also be a file permission problem, I always face this issue when i download images from my email and use them directly.
If you are working locally on a mac:
- Right click on the selected image
- click on **get info**
- In sharing and permissions, make sure that the **everyone** has the **Read only** permission instead of **No access**
If you are working directly on a live server:
- login using FTP (with any ftp client such as File Zilla)
- Go to the selected image
- Right click and select file permissions
- set permissions to : **664**
Ok, so basically, I replaced the not-working /style/main.css with the copy of it (test.css - described in post comments) and now it works. Why is still the question, but the problem is kinda solved I guess.
Same with me, I guess images that used in css must be in the same folder as css file. I tried every possible solution while checking with the browser tool and the only thing that works is when I put the image and stylesheet in the same folder.
I am having the same problem. Working with Visual Studio Community.
I went inspect elements in browser and found that the file directory "automatically" (i did not set it this way) says that my image folder is nested inside my css folder. dont know why yet... so I then went and moved my image folder into my css folder seeing that this is what my browser showed me in the dev tools...
so maybe for some reason when working with css your images inside your image folder should be located in your css folder and not the complete Webpage Folder..it worked.

CSS Relative link playing up

I am trying to include a background image using a relative link in the css.
My tree looks like this
/_css
/_css/gcrm.css
/_images
/_images/bg-grad1.gif
The css I am using to use to call it is like so
background-image: url(../_images/bg-grad1.gif);
It displays as expected in Visual Web Developer however when I put it on the web, no background. When I inspect element in Chrome this is the linked file
mysite.com/_css/../_images/bg-grad.gif
Unfortunately I cannot link to it with the / root as I am trying to setup SSL and my hosting company has allowed us to use as shared cert that mirrors the site 1 level deep in the domain tree.
I must be missing something incredibly simple but I can't figure out what it is to get it working.
Your url looks fine in regards to your file structure. Assuming this is your file structure:
/_css/
...
gcrm.css
...
/_images/
...
bg-grad1.gif
...
From the fact that it's actually outputting the .. in the url in the code, maybe you need to enclose the url in quotes:
background-image: url("../_images/bg-grad1.gif");
Use following code:
background-image: url(../../_images/bg-grad1.gif);

convert a jpeg into url for css

I am new to web design and I think I need to convert a jpeg into a url. I have an image saved locally on my computer. An example website that I am using as a reference has a one page for their html/source code and a different page for their css. All of the images are listed under the css page, however, they are typed in as a url. For example url(..green sea.jpeg) When I try to replace their css code with my image, it can't be found. I know I'm new, so I figure I must be making a simple simple mistake, but everytime I try and look it up online, I find directions on how to convert a jpeg into a url and it looks like you need another kind of software to do this, but I'm not exactly sure. Any help/direction would be very much appreciated!
Thanks!
When you replace your image name for the one you see in the CSS:
url(..green sea.jpeg)
...make sure that the image you are wanting to use is in the same location (folder / place) as the green sea image.
So if I want to replace it:
url(..myNewimage.jpeg)
I would make sure it was in the same place as the image I'm replacing it with.
ALSO, I just noticed that your path is wrong. You have ".." when it should probably be "../".
So try this:
url(../green sea.jpeg)
The url you need for your code is just wherever you have posted the image on your server in relationship to the css file. For example, if your directory is structured like this:
/CSS
-style.css
/JS
/images
-green-sea.jpg
index.html
Then your url would be (../images/green-sea.jpg)

Resources