简体   繁体   中英

How to link a HTML page to a CSS file when the CSS file is in an upper directory?

There is my problem: Since I had some organization issues with my website, I wanted to arrange my files to a better classification.

Now, the folder tree looks like:

  • www
    • ressources
      • images
        • ...
      • css
        • design.css
    • mypage1
      • index.html
    • mypage2
      • index.html
    • index.html

And now I don't know how to link the css file to the pages stored in a folder like the "mypage1" folder. To start from my C: drive will will produce path errors once online, I tried the "shortcuts to the css file in each folder" solution too, but I think there is a far better way to proceed. Need some help!

Thanks again!

use the link:

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

here, used ../ going back folder..

You can use:

<link rel="stylesheet" href="../ressources/css/design.css" type="text/css" media="all">

The .. will go one directory top. Since the html files are in a directory (like mypage1 ), this will go to the parent directory, which is www . Then the next that should be done is to pass the directory path to your CSS file, which in your case is /ressources/css/design.css .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM