1

Please help to check why I cannot link club.css to index.html.

index.html (Please note: I have to use the direct local path as the CSS link, or it will show that "some content has been disabled in this document.")

<head>
    <meta charset="utf-8">
    <title>The California Corgi Dog Club</title>
    <link rel="stylesheet" type="text/css" href="C:\Users\leeson\Desktop\CS651 Web Systems\assignment\assignmentfall2021-Rijutady\clubProject\club.css" />
</head>

club.css (Please note that the css file is under Encoding utf-8)

h1 {
    background-color: skyblue
}
Kusal Darshana
  • 159
  • 2
  • 18
huiqing wu
  • 19
  • 1

5 Answers5

1

The Simple Answer

Using a relative path should resolve your issue for most situations.

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

The Alternative

You could also include the CSS directly into the HTML document, however this is not always ideal or recommended. Here's an article on that.

<style>
  h1 {
    background-color: skyblue
  }
</style>
Delta
  • 444
  • 1
  • 4
  • 14
1

@NullPointDev's answer is correct. Use Relative path to your projects. It will make your work easier without errors. I just put some additional information for make your project easier.

  • If both HTML and CSS files in same directory, You can link your CSS like this,

<link rel="stylesheet" type="text/css" href="club.css"/>
  • If the CSS file is located in another directory in the directory which the HTML file located, you can use this method.

<link rel="stylesheet" type="text/css" href="name_of_the_subdirectory/club.css"/>
  • If the CSS file located in out of the directory which the HTML file located, Use ../ to go back.

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

Read this Article for more info. Relative Path | W3 Schools

Now you know all the basics of Relative path. Wish you all the best.

Kusal Darshana
  • 159
  • 2
  • 18
  • 1
    Thanks for covering those extra cases, I didn't really think to mention them because of the way that the original question's example referenced the CSS's path, but this is definitely quite a bit more descriptive. – Delta Sep 01 '21 at 11:00
0

no ,

it will be <link rel="stylesheet" type="text/css" href="club.css" />

if its under the clubproject

Sarvesh
  • 95
  • 1
  • 13
0

The solution code for your question is:

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

Your mistake : You have written the complete folder path instead of relative file path.

Advice: Have a look to the below link to clear concept. https://www.w3schools.com/html/html_filepaths.asp

-1

I prefer simple solution which is using relative path.

club.css

<link rel="stylesheet" type="text/css" href=".\club.css" />

Where is the problem:

URLs cannot contain spaces

WPPlumber
  • 376
  • 2
  • 9