Consider the following style declaration in a stylesheet:
background-image: url('path/to/image');
That's really all I'm trying to accomplish, but I'm running into difficulties using Visual Studio 2005 on my ASP page.
The problem is that I'm unable to find a good way to refer to the "document root" within those 'url' attributes in the stylesheet. I understand I could use the '~' mark, in an asp.net control, to refer to the document root, but it doesn't work within the 'url' declaration in a stylesheet. Also, simply using '/' doesn't work, since that ends up referring to a directory much higher up in the directory structure, something like my C: drive.
The solutions I've found are to do something like "url(../path/to/images)". That works, but it's ugly, and I'd like to base the paths on the document root, not the directory my stylesheet happens to be in.
I can also include the entire full path to the image directory, relative to my C: drive, but that's even worse, and it won't work once the site is published.
So, is there a "DOCUMENT_ROOT" type of value I can use, or can I set the document root behavior for a given website in Visual Studio?
Thanks.
Have you tried background-image: url('/path/to/image');? I think just having the first slash will take it to the docuemnt root. I could be wrong though.
Having just the first slash doesn't work. I'm not sure where the "/" brings it, but I think it's probably going back to the root of my hard drive. In either case, it's not finding the proper path that way.
It comes down to there being a disconnect between the way web pages function (where "/" should bring you to the root of the site) and the way Visual Studio treats things (where "/" seems to bring it to the filesystem room, instead of the root for that particular website/project.
Is there a way to convince Visual Studio to see "/" as the root for that website, instead of some place further up the directory structure?
this may not be useless to remind that relative pathes in external stylesheet MUST be RELATIVE to the very CSS file itself. (Obvious since the same css file can be linked by many remote pages)therefore url(../path/to/images) is not so ugly ;-)Using absolute path, one can try to concatenate with Request.ApplicationPath & "path/to/image/"...
With Request.ApplicationPath, I think that would only work in a .aspx file, not in a .css file, but I'll see if it does anything.
hum... using aspx for css file would prevent the web designer to edit it. I would rather have the css file next to the image directory and use relative path into the css. the page only needs to know wher the css is.
It turns out all I needed to do was to modify the "Virtual Path" property on the website, to "/" instead of "/MySiteName". The reason I didn't notice this was because I didn't have SP1 installed, and it's not available in the normal, installed version.
Thanks for the suggestions.
0 comments:
Post a Comment