Skip to content Skip to sidebar Skip to footer

Linking CSS File On A HTML Document In Same Directory On My Hard Disk (Windows)

I am using Windows (7) trying to create an offline html page that should link to a separate CSS file located in same directory. I tried to use Copy

to address through parent folder, use:

<link rel="stylesheet" href="../style.css">

to address through the internet( CDN ) use:

<link
  rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3./css/bootstrap-theme.min.css"
  >

to address through your hard drive use:

<link rel="stylesheet" href='file:///C:/mystyles.css'>

Solution 3:

While the accepted answer is not wrong it's over-complicate things.

If your file is https://www.google.com/b/bananacream/bananas/index.html

<link  href="/style.css">

Will try to get https://www.google.com/style.css

<link  href="style.css">

Will try to get https://www.google.com/b/bananacream/bananas/style.css as nothing indicate what folder the file is located in it will use the same folder as the requesting file.

<link  href="./style.css">

Will try to get https://www.google.com/b/bananacream/bananas/style.css as ./ tell that the file is located in the same folder as the requesting file.

<link  href="../style.css">

Will try to get https://www.google.com/b/bananacream/style.css as ../ tell that the file is located in the previous folder as the requesting file.

<link  href="../../style.css">

Will try to get https://www.google.com/b/style.css as ../../ tell that the file is located in the folder two steps before as the requesting file.


Solution 4:

try this one, it worked for me.

 <link rel="stylesheet" href="./main.css">

Post a Comment for "Linking CSS File On A HTML Document In Same Directory On My Hard Disk (Windows)"