Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Background Image Won't Display

in Visual Studio and Webmatrix



8:55 am on May 28, 2011 (gmt 0)

I am using Visual Studio 2010; my 'doctype' is XHTML 1.0 Transitional; viewing in Chrome11 and IE8.

The reason I am using VS is to take advantage of 'master pages'...love, love, LOVE them! My skill level is somewhere between beginner and intermediate...graduating next month with an AS is Web/Database Technology.

Problem: I have intermittent issues with background images; not only in VS, but also with Notepad++. I don't have problems with displaying any images in my HTML code, nor do I have a problem with background colors.

My code is simple:
background: url(images\circles.jpg) no-repeat right;

It's the EXACT same code I used when I created the page with Notepad++.

I have doubled-checked my spelling on the image file and that it is in the correct directory...other than that, I don't know what the problem could be. As I said above, this is not the first time this has happened, but it doesn't always happen.

Any thoughts on this issue would be appreciated. Thank you.


3:49 pm on May 28, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Is this a direct cut-and-paste?


4:08 pm on May 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

HTML will accept a backslash instead of a forward slash in your file paths, but CSS will not.


5:55 pm on May 28, 2011 (gmt 0)

@Lucy - Yes...copy/pasted it from the CSS file I created with Notepad++

@Robzilla - I tried both a forward and backward slashes...neither worked.


6:29 pm on May 28, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

XHTML 1.0 Transitional

Given this DOCTYPE I would suggest putting the filename in quotes:

html, body {
background: url("images/circles.jpg") no-repeat right;

I would not use a backslash.



9:27 pm on May 28, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Try this:

Break your "background" definition into its component parts and name each one separately:

{background-image: url("images/circles.jpg");
background-repeat: no-repeat;
background-position: top right;}

Officially this should make no difference whatsoever, but it's always good to try. For any CSS issue (margins, for example), not just this specific one.

I wouldn't set the background for both "body" and "html". They're different things, so you're just giving browsers another chance to act up. Pick one or the other.


9:29 pm on May 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

Try converting the image into a base64 representation and put that in your background attribute. If the image still won't show, the problem's elsewhere in your code (which seems more likely to me at this point).


5:55 pm on May 29, 2011 (gmt 0)

@Samizdata - I tried single and double quote...no go.

@Lucy - Broke it down...no go.

@Robzilla - There is nothing wrong with my code...seriously. As previously noted, I wrote this page as a sample site with four files (index.html, master.css, bandpic1.jpg and circles.jpg) and it loads just fine. I wanted to expand it to a full site for a potential client and so I basically dumped it into VisualStudio (coding in C#) so I could take advantage of 'masterpages' and other features.

The only changes I made to the original index.html as to divide it into 2 files; masterPage.master and default.aspx. The master.css is exactly the same and that is where my 'background' code is at. There is absolutely NO reason for it NOT to work...it's frustrating!


7:28 pm on May 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hi there Geckko,

without a link to the site in question, I don't see how anyone here can really find a solution to your problem. :(



7:38 am on May 30, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi Geckko [webmasterworld.com], and a warm welcome to WebmasterWorld :)
Yes, it is frustrating! So I appreciate you haven't made a huge code dump or linked out to a draft page that will disappear leaving later readers without any clue of what the problem/solution was/is. I am thinking I'd like to see some code just like birdbrain, but there are a couple of basics still to try - can you just work through the following and let us know if it produces any clues.

Ok, it looks like you've done a great job problem solving so far. Although you didn't exactly say what the issue is I'm assuming the image isn't visible. I'm also intrigued by your statement this is an intermittent problem. Is it just some images/code, or just one image/code that sometimes fails to show?

Note often this is simple, so it is doubly important to work through the basics. I understand you are a fan of Visual Studio ( I'm a fan of my favourite editor too), but unless VS's features are causing the issues, focus on the code and how it is performing in the browser.

For that reason always test in a browser rather than the internal "preview" in the editor. Check in a range of browsers to see if results vary, and use the developer tools to check the code is being assembled properly and the styles being applied to the element.

Then run through the following steps, which include those already suggested - but this time testing the results in each browser as you make changes, and noting if the results vary.
  1. Double-check there is no gap between url and the open bracket
  2. Validate your html [validator.w3.org] and css [jigsaw.w3.org]. Typo's are easy to make, so validate often, especially when code isn't behaving as you want.
  3. Definitely change the backslash in the url. Windows won't mind, other servers will.
  4. Try quoting again (But don't be disheartened if it doesn't work - never does for me either ;) )
  5. Check your background-position. If there is only one keyword (right) the other will default to center. This particular image in this particular code it may be enough to make the image "un-see-able". Try something simple like
    background-position: top left;
  6. Use the developer tools to check the image is being called, but double-check by calling it as an image element in the html, and then by setting as the background on a block level element with an explicitly declared width and height large enough for the whole image to show.
  7. If the image still does not display, test using a different image.

And if none of that identifies the solution, come back and we can look at the next problem-solving steps.

Edit Reason: Clarification


2:50 am on May 31, 2011 (gmt 0)

@Bird - I know, but I won't have a place to upload it until week after next.

@alt - I've tried everything I could think of...backward/forward slashes, taking it out of the 'images' directory and putting it in the root directory, adding a '~', single and double quotes, breaking it down to individual components, tried another picture, ran a code analysis, etc.

I'm not a 'fan' of Visual Studio per se...I'm a 'fan' of masterPages. WebMatrix has something similar with Layouts without the bulk of Visual Studio, but as stands, I'm not too thrilled with their current set up. Fortunately, I'm attending a conference this weekend and I'm going to get the opportunity to meet with the developers of WebMatrix and do some serious picking of their brains. WebMatrix has the potential to be a web designers best friend...somewhere between Notepad++ and Visual Studio...so long as they don't screw it up.

But that's a discussion for another day. In the meantime, it'll be a couple of weeks before I have a website that I can post at and I'm in no big hurry...it's not for school or for a client.


5:52 am on May 31, 2011 (gmt 0)

Ok...how weird is this? I'm having the same problem in WebMatrix when I try to set up the site with a _layout format.

Then I thought...ok, it worked with Notepad++, so what am I doing different? So using WebMatrix, I made an index.html and default.cshtml page...and both worked.

So is the problem that I'm trying to create 'masterPages'...which would REALLY bum out if it was 'cuz I really like them? But then again, I just taught my ASP.NET how to create a website using 'masterPages' and it worked beautifully...so what changed?

So I opened up several instances of Explorer and started looking at my directories of where I created this website in Notepad++, Visual Studio and WebMatrix, AND my project from class.

And the light dawned. It's not my code at all...the code is perfect and works in Notepad++, Visual Studio and WebMatrix...once I made one tiny little change; I put the .CSS file in the root directory (and changed the link of course).

Of course, this brings up a NEW problem...why all of a sudden isn't is working when then is NOT the first time I have placed my .CSS file into a separate directory and it has worked before?

I started thinking that maybe it was because of the way I was coding the link:

<link href="master.css" rel="stylesheet" type="text/css" />

whereas before I have

<link type="text/css" href="css/master.css" rel="stylesheet" />

and even

<link rel="stylesheet" href='css/master.css' type="text/css" />

So I tried variations as above...I even changed the name of the folder to 'css'...didn't work.

So now we have an even more interesting problem...how come putting my .css file a separate folder SOMETIMES doesn't work?


7:11 am on May 31, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

You don't happen to have any rewrites do you? I've been bitten by that one more often than I care to say ::sob::


6:24 pm on May 31, 2011 (gmt 0)

Lucy -

Not sure what you mean by 'rewrites'?


10:16 pm on May 31, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Not in your CSS. In the htaccess for utterly unrelated reasons. I admit this is grasping at straws, but if your user is on a particular page and the server thinks they're on a different page, relative links including css and images will fall apart. (I learned this 4+ years ago. And 4 years ago, and 3 years ago, and yesterday... and eventually it will stick.)


3:12 am on Jun 1, 2011 (gmt 0)

Oh ok. I don't think that that is the issue because with the exception of the background-image file...all the rest of the CSS is applied.


3:36 am on Jun 1, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Luce, brilliant lateral thinking!

@Geckko: But you are saying this is an intermittent problem depending where you put the files, and the css is looking for a path to the background-image so this could easily still be a re-write issue.

However, take this back one step for a moment.
  1. Has your course covered absolute and relative paths yet?
  2. If so, have you tried absolute paths in the <link> and the url to the background image?
  3. When you "view source" (in the browser, not the editors internal preview), are the paths the same as the ones you coded in?


7:42 pm on Jun 2, 2011 (gmt 0)

alt -

1. Yes...we covered both 'paths' the first year.

2. Unless you know the directory structure of your host server, you NEVER use absolute paths. Because while YOUR 'image' files maybe located at
E:\Websites\circles\images\circles.jpg the 'path' for the host is going to be www.webmasterworld.com/images/circles.jpg

3. I'll have to check that out and get back with you. I had 'fixed' the problem and will have to put it back and test it.

Featured Threads

Hot Threads This Week

Hot Threads This Month