Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

css

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

like image 345
Joe Isaacson Avatar asked Dec 09 '22 12:12

Joe Isaacson


1 Answers

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)

like image 127
SpliFF Avatar answered May 19 '23 01:05

SpliFF