When to use . when referring external stylesheet in CSS

Someone on here told me that each . represents the number of files you have to exit. In this case, shouldn’t . be present in the link href from index.html to style.css. This is because you have to exit index.html right?

So lost.

Hello @board1774168228. My understanding is that it isn’t files that you have to exit, but rather folders. So if your style.css and html.css are in the same folder (or your HTML file is not in a seperate folder to , then you don’t need the .. If you had a file system like this:

>project
>>html >>css
>>>index.html >>>style.css

(with each added > representing a layer deeper. Inside the html folder, there’s the index.html, and inside the css folder, there’s the style.css), then you would need to have a ., as you have to exit the html folder, and then go to the css folder, then the css file itself.
I hope this helps!

2 Likes

makes sense thanks man!

1 Like

Close, but not quite. :slight_smile:

A single period . denotes the current working directory, and a double period .. denotes the parent directory.

So, if your directory looks like this:

project
|
+---css
|       style.css
|
\---html
        index.html

then to link style.css from index.html, we would need to write:

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

as we need to go up to the parent of html, before going down through css to get the stylesheet.

If we wrote ./css/style.css, we would be attempting to find the file in project/html/css/style.css. :slight_smile:

2 Likes

sorry this is so late but thanks a lot bro!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.