Joe Isaacson
Joe Isaacson

Reputation: 4132

How should I link a CSS file for the subdomain from the main domain?

I may be using subdomains incorrectly here instead of using sub directories, but I want to import the same CSS into my subdomain (hire.joeisaacson.com) from my main domain (joeisaacson.com)

The current file structure is below

public_html (where joeisaacson.com points to)
-index.html
-css
--style.css
-hire (where hire.joeisaacson.com points to)
--index.html

I want to access style.css from the "hire" folder instead of creating a duplicate and having to updated both.

using ../css/style.css from the "hire" folder doesn't work, because it searches within hire.joeisaacson.com and not joeisaacson.com

Upvotes: 4

Views: 8338

Answers (2)

SpliFF
SpliFF

Reputation: 39014

When you have a case that the same source code will be used at different nesting levels (like /index.htm and /hire/index.htm or different domains you might want to consider the HTML BASE tag.

<base href="http://joeisaacson.com">
<link rel="stylesheet" href="/css/style.css" type="text/css">

This will fetch the CSS from http://joeisaacson.com/css/style.css regardless of where the HTML page is served as long as you realise it will do this for all external resources (images, css, js, etc).

Just be sure BASE tag is inside HEAD and comes before any linked content. You also do not close this tag in HTML (so no </base> or <base /> is expected)

Upvotes: 14

Ganesh Pandhere
Ganesh Pandhere

Reputation: 1652

you should provide absolute path in that case for including on subdomain. It should be looking something like :

http://joeisaacson.com/css/style.css

Upvotes: 0

Related Questions