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

后端 未结 2 2018
悲哀的现实
悲哀的现实 2021-01-06 18:01

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

相关标签:
2条回答
  • 2021-01-06 18:29

    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/#

    0 讨论(0)
  • 2021-01-06 18:37

    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">
    
    0 讨论(0)
提交回复
热议问题