简体   繁体   中英

CSS file not linking to HTML file (same folder)

I have this:

<head>
<title>1</title>
<link rel=“stylesheet” type="text/css" href=“style1.css”>
<script src="script.js"></script>
</head>

I've tried many things. removing the type, adding a / at the end, adding a./ before style1.css, etc. Both the html file and the css file are in the same folder. The html works. here is the css:

p {
    color: red;
}

h1 {
    color:blue;
}

where did I go wrong?

check your quotations around your attribute value, just replace your link with below, and hopefully, this should work:

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

It seem you are using wrong double quotes symbol in the link tag

<link rel=“stylesheet” type="text/css" href=“style1.css”>

It should be

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

replace this line

<link rel=“stylesheet” type="text/css" href=“style1.css”>

with

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

 p { color: red; } h1 { color:blue; }
 <.DOCTYPE html> <html lang="en"> <head> <title>1</title> <link rel="stylesheet" type="text/css" href="style1.css"> <script src="script.js"></script> </head> <body> <p>this is paragraph</p> <h1>this is h1 heading</p> </body> </html>

your reference to the stylesheet look like this

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