-2

For some reason, my CSS file will not link to my HTML file. I have tried different paths and browsers. When I inspect the elements of the page and look under resources, it doesn't show up.

Here is my HTML:

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
    <link rel="stylesheet" herf="/CSS/fun.css" />
    <title>Task Sheet</title>
</head>
<body>
    <div class="w3-container w3-white middle border">
         <h2>Daily Task</h2>
         <button type="button" name="button" onclick="test()">Button</button>
         <form id="t1">
             <input type="checkbox" name="task1" value="task1"> Task 1 Test</input>
         </form>
    </div>
    <script src="/Users/ddjhende/Desktop/Fun Website/JavaScript/fun.js"></script>
</body>

  • 5
    `href` not `herf` – Feek Jan 22 '17 at 20:07
  • And please, stop using the `/>` ending for self-closing tags. It's **not needed** Also, stop using capital letters in folder-names, and also spaces in folder-names for web-development. – junkfoodjunkie Jan 22 '17 at 20:10
  • 3
    @junkfoodjunkie But `/>` is not bad practice. – Oriol Jan 22 '17 at 20:11
  • 1
    @junkfoodjunkie You're presenting personal preferences as fact. – ceejayoz Jan 22 '17 at 20:12
  • Is it needed? No? Okay, then it's not a statement of personal preference, my statement was perfectly valid. As for the second sentence, using spaces in folder-names is a definite bad practice, and using upper-case in folder-names might bite you in the ass when you put the code somewhere where casing matters for file- and folder-names. – junkfoodjunkie Jan 22 '17 at 20:14

2 Answers2

0

At line 5 you have written

<link rel="stylesheet" herf="/CSS/fun.css" />

instead you should try

<link rel="stylesheet" href="/CSS/fun.css">

Normally you also define a type

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

But to be honest i don't think that's necessary nowadays...

Edit: Since people seem to love the closing tag, I'd like to add this.

Use the closing tag as much as you like. However, if you have multiple links you should be consistent. Pick the version you want to use and use it in all cases, otherwise it can look confusing and that is not good practice under any circumstances.

Community
  • 1
  • 1
Oscar Lundberg
  • 433
  • 4
  • 14
0

The problem might be on the path.. What is the path of your css file and html file in your system? Could you explain more in order for us to help you? For example :

  • css file C:\myproject\css\style.css
  • html file C:\myproject\main.html

Before you check for your path you should also correct the typo:

<link rel="stylesheet" herf="/CSS/fun.css"/> 

href not herf.

George Linardis
  • 130
  • 3
  • 11