Moved HTML into a different folder, now it's not linking CSS correctly

后端 未结 2 579
Happy的楠姐
Happy的楠姐 2021-01-29 05:32

I created a header (header.html) file to be imported into different pages on my site. It works when I have it only in the WebContent folder, and draws the CSS files, fonts, and

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

    Simply use absolute path for your CSS & JS & Fonts & other assets

    How?

    Instead of

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

    write

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

    and make sure if assets directory is in directory for which point your domain

    In many cases absolute paths are better, because You don't have to think how to link to your assets from specific directory, because this path always start from root directory

    Here is similar question & answer

    0 讨论(0)
  • 2021-01-29 06:15

    providing the folder structure has both user and assets mentioned above in the parent directory simply change

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

    To

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

    This is a relative link meaning it will go up one structure and go from there.

    But you need to consider the location from which file it is called as we don't know your directory structure this is the best we can do with the information you've given.

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