简体   繁体   中英

Issue with CSS/ HTML Link

Could anyone tell me why my page isn't linking to the CSS ? I have both HTML and CSS file in the same folder.

Here's my HTML :

<!DOCTYPE html>
<html>
  <head>
      <link rel="stylesheet" type = "text/css" href="style.css">
      <title> Flying Fish Painting Company </title>
  </head>
  <body>
     <h1> Flying Fish Painting Company </h1>
  </body> 
</html>

And this is my CSS :

h1{
    color:blue;
  }

It works fine for me.

If I put both files in the same folder then it also works

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

if you put your CSS file in a different folder that time.

Syntax:

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

You should write:

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

Could you check the spaces:

type = "text/css"

change to:

type="text/css"

Is this your exact html code or just an example?

There are a couple of spaces before and after your = on the type you should remove.
Personally I find it better to put all css in a subfolder. It shouldn't make a difference however it makes for easier organization.
For a single css style like that I would just put it in line the html unless this is something you want across several html files.

There is nothing wrong with this code except the spaces mentioned above. Works fine for me. Check for typos and make sure it is in the same folder.

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