1

I have a website where I am referencing the CSS/JS in the root directory. I want to create a sub-section of the website under it's own directory. The problem is that I am referencing the CSS/JS in the main directory and I want to know what the best way to reference the CSS/JS would be for the subdirectory.

If I just use the http address for the files it works, but I think there could be a better way to go about this. Does anyone have any opinion on the matter?

user2917239
  • 898
  • 3
  • 12
  • 27
  • Use a relative path always you can ... http://css-tricks.com/quick-reminder-about-file-paths/ and http://stackoverflow.com/questions/5815452/how-to-use-relative-absolute-paths-in-css-urls – DaniP Dec 26 '13 at 19:34

1 Answers1

2

You can use ../ to specify the parent directory when using relative paths. So for example, if your file structure is something like this:

root
    index.html
    style.css
    javascript.js
    subdirectory
        subpage.html

Then in your subpage.html file, use:

<link rel="stylesheet" href="../style.css">
<script src="../javascript.js"></script>
Dryden Long
  • 10,072
  • 2
  • 35
  • 47