CSS Reference Issue

245 Views Asked by At

I was hoping someone may be able to help out with an issue.

I have a site that is accessed through a root domain (originalDomain.com) and the CSS is linked as below.

<link href="../../Styles/Css/style.css" rel="stylesheet" type="text/css" />

This all works fine

However I can also access this site on a different domain. Rather than the absolute root of the domain this one is accessed at newDomain.com/login. This still points to the files at the location of the original domain but because of the /login is unable to locate the CSS file. I assume the ../../ takes it to newdomain.com rather than newdomain.com/login.

Is there an easy way to have a single CSS reference without any back end code changes that will allow the CSS to be successfully referenced at both of the above scenarios.

I hope this makes sense.

Any help is greatly appreicated.

2

There are 2 best solutions below

3
On

Give absolute paths and not relative ones

<link href="/path/to/css/style.css" rel="stylesheet" type="text/css" />

Note the first character is a / (slash)

0
On

If your <head></head> tag contains runat="server" you can simply specify it as:

<link rel="stylesheet" type="text/css" href="~/CSS/Style.css" media="screen" />

Taken from here