user18681
user18681

Reputation: 31

How do I link external style sheet to multiple pages and folders?

im building a pretty large website that will have many pages and folders. I have 1 stylesheet.

How do I add the style sheet to "ALL" of these folders? I didnt have this problem before I started to put the pages in SEPERATE folders. Now that each page has its own folder it no longer reads my stylesheet unless its in the SAME folder

Example, lets say I have a folder of pets, another of cars, and another of planes. I have to put my stylesheet in EACH and everyone of these folders so that I can see my site. How can I do it so that I do NOT have to put a stylesheet in each and every folder?

In other words how can I get my stylesheets on the same page as my folders without having them in that folder? How can I get them to communicate while being in a different folder?

Upvotes: 3

Views: 16608

Answers (2)

user1193509
user1193509

Reputation:

If a file is linked above the current directory (meaning the file you want to link is outside of the folder where the linked document is stored) you have to write it like this:

../file.html

If it is above the current directory and inside a different folder, you link like this:

../diffFolder/file.html

If it is deeper in the current directory (meaning it is within a folder of the current directory) do it like this:

deeperFolder/file.html

The other option of course would be to create a php header document and require/include it in your other pages. It really is the way to go with big sites that reuse content. I am working on a smallish website right now, but every part that is reused is it's own individual document that is required server side whenever the link is called. So if I make a change to the header, it affects every page. Same with footer, sidebar, etc.

This website actually explains dynamic inclusion on a pretty basic level quite well: http://inobscuro.com/tutorials/php-dynamic-includes-16/#

Upvotes: 1

milo5b
milo5b

Reputation: 160

You need to refer to it with root-relative or absolute path instead of relative:

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

instead of "style.css" refer to it as "/this/is/my/path/to/my/files/style.css". If your file is in the root directory would be "/style.css"

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

If you'd like to have an absolute path:

 <link rel="stylesheet" type="text/css" href="http://www.mysite.com/path/to/style.css">

Upvotes: 1

Related Questions