Specify a Root Path of your HTML directory for script links?

前端 未结 7 884
我在风中等你
我在风中等你 2020-12-23 03:11

I\'m writing a template for dreamweaver, and don\'t want to change the scripts for subfolder pages.

Is there a way to make the path relative to the root directory?

相关标签:
7条回答
  • 2020-12-23 03:45

    Just start it with a slash? This means root. As long as you're testing on a web server (e.g. localhost) and not a file system (e.g. C:) then that should be all you need to do.

    0 讨论(0)
  • 2020-12-23 03:54

    / means the root of the current drive;

    ./ means the current directory;

    ../ means the parent of the current directory.

    0 讨论(0)
  • 2020-12-23 04:01

    use two periods before / , example: "../style.css"

    0 讨论(0)
  • 2020-12-23 04:04

    To be relative to the root directory, just start the URI with a /

    <link type="text/css" rel="stylesheet" href="/style.css" />
    <script src="/script.js" type="text/javascript"></script>
    
    0 讨论(0)
  • 2020-12-23 04:04

    I recommend using the HTML <base> element:

    <head>
        <base href="http://www.example.com/default/">
        <link rel="stylesheet" href="style.css" />
        <script src="script.js"></script>
    </head>
    

    In this example, the stylesheet is located in http://www.example.com/default/style.css, the script in http://www.example.com/default/script.js. The advantage of <base> over / is that it is more flexible. Your whole website can be located in a subdirectory of a domain, and you can easily alter the default directory of your website.

    0 讨论(0)
  • 2020-12-23 04:05

    This is oddly confusing to me. I know it shouldn't be. To check my understanding, I'd like to use a family relations model to compare. Assuming "You" is the current webpage, is the following correct?

    <img src="picture.jpg">            In your folder with you, like a sibling
    <img src="images/picture.jpg">     In your child's folder, under you
    <img src="../picture.jpg">         In your parent's folder, above you
    <img src="/images/picture.jpg">    In your cousin's folder
    

    So, up to parent, over to sibling, down to their child = your cousin, named "images".

    0 讨论(0)
提交回复
热议问题