Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-09-2012, 01:45 AM   PM User | #1
Yaz1994
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Yaz1994 is an unknown quantity at this point
Background image not working Css

Hi, This is my first post here! I am stuck with some CSS, I am trying to link an image to my stylesheet but it does not work unless it is in the style sheet folder bearing in mind that the image is in a diffrent folder. My folder structure is:
- As > Css > style.css
- As > images > banner.jpg

when I do <img src="..\images\banner.jpg"> the image works perfectly fine, when I put that into my css nothing comes up:
background-image:url('..\images\banner.jpg');

tried a lot of diffrent things such as:
background-image:url('\images\banner.jpg');
background-image:url('..\images\banner.jpg');
background-image:url('..\..\images\banner.jpg');

I'd be very grateful if someone is willing to help me fix my issue!
Thanks!!!

Last edited by Yaz1994; 11-09-2012 at 02:05 AM..
Yaz1994 is offline   Reply With Quote
Old 11-09-2012, 06:39 AM   PM User | #2
JT Web Design
New Coder

 
Join Date: Jun 2012
Location: Burnley, Lancashire UK
Posts: 11
Thanks: 0
Thanked 3 Times in 3 Posts
JT Web Design is an unknown quantity at this point
try

background-image:url('images/banner.jpg');
JT Web Design is offline   Reply With Quote
Old 11-09-2012, 10:47 AM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,602
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
If your directory structure looks like this:
Code:
/css
  style.css
/images
  banner.jpg
page.html
… i. e. the HTML file is at the same level as the directories, your relative file paths must look like this:
Code:
<img src="images/banner.png" …>

or

background-image: url(../images/banner.jpg);
Note the forward slashes.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 11-09-2012, 12:45 PM   PM User | #4
Yaz1994
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Yaz1994 is an unknown quantity at this point
Thanks

Hmm, the folder structure is
As> css > style.css
As> images> banner.jpg
As > html > index.htm

+ this is not on a server this is on my computer but none of them work :/ anything else?
Yaz1994 is offline   Reply With Quote
Old 11-09-2012, 01:09 PM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
the urls you are using are nto working becuase you are jsut viewing the page from your web broswer without a server, so you will have to use local file links instead Im nto even sure if this will work in css but you can try :



background-image: url('file://c:/localfoldertofiles/images/banner.jpg');

( honestly you should get a test server or a temporary site to post your code on because its not going to look and react how it should without the support of a web server and when you finally have to upload your work to a server, none of the links will work)
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 11-09-2012, 02:23 PM   PM User | #6
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Or install xampp on your PC.
SB65 is offline   Reply With Quote
Old 11-09-2012, 05:15 PM   PM User | #7
vjm
New Coder

 
Join Date: Nov 2012
Location: PH
Posts: 16
Thanks: 1
Thanked 2 Times in 2 Posts
vjm is an unknown quantity at this point
Quote:
Originally Posted by Yaz1994 View Post
Hmm, the folder structure is
As> css > style.css
As> images> banner.jpg
As > html > index.htm

+ this is not on a server this is on my computer but none of them work :/ anything else?


I see that all your files are in the folder named "As" and inside it are the folders named css, images & html. The file "style.css" is inside the css folder, then the "banner.jpg" file is inside the images folder and lastly the "index.htm" file is inside the html folder. If this is correct, I suggest this:

*In the HTML file, use this href where you link your css file:
href="../css/style.css"

*In the CSS file, use this in your background-image tag (always use forward slashes):
url(../images/banner.jpg)

Note: You don't need to install xampp. As long as you're not using server-side language for your web pages.

Last edited by vjm; 11-09-2012 at 05:20 PM.. Reason: Grammar
vjm is offline   Reply With Quote
Users who have thanked vjm for this post:
Yaz1994 (11-09-2012)
Old 11-09-2012, 11:25 PM   PM User | #8
Yaz1994
New to the CF scene

 
Join Date: Nov 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Yaz1994 is an unknown quantity at this point
Thanks

Thanks everyone for having a go at helping me! VJM, I am very grateful for you solving my problem! Thank you and thank everyone that contributed! Really appreciate it!
Yaz1994 is offline   Reply With Quote
Old 11-10-2012, 01:23 AM   PM User | #9
waxdoc
Regular Coder

 
Join Date: Jul 2008
Posts: 155
Thanks: 9
Thanked 13 Times in 13 Posts
waxdoc is an unknown quantity at this point
slant?

What am I missing?

Why are your slashes \ slanting backward,
Code:
<img src="..\images\banner.jpg">
instead of forward / ?
Code:
<img src="jmWEB/floral/57PurinaPoster.jpg"  />
Basically, in HTML, you use ../folder to "dig out of a nested folder" so, if its nested two folders down, you use two ../../folder.
waxdoc is offline   Reply With Quote
Old 11-10-2012, 03:17 AM   PM User | #10
vjm
New Coder

 
Join Date: Nov 2012
Location: PH
Posts: 16
Thanks: 1
Thanked 2 Times in 2 Posts
vjm is an unknown quantity at this point
You're welcome Yaz1994! I'm happy that I helped you with your problem.
vjm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:56 PM.


Advertisement
Log in to turn off these ads.