简体   繁体   中英

My CSS file won't link and I don't know why

I'm trying to link p1.css to p1.html, but for some reason it's not working. It's in a file on my desktop called 115, and in a file inside called css, but no matter what I add or take away it won't show up. What am I doing wrong?

<!DOCTYPE html>
<html lang="en">
<head>
<title>CIS 115 - Project 1</title>
<p lang="en"></p>
<meta charset="utf-8">
<meta name="Project 1" content="">
<meta name="Kim Peoples" content="Kim Peoples">
<link rel="stylesheet" type="text/css" href="115/css/p1.css">
<script src="115/p1/p1.js"> </script>
</head>

this is the css, which is I'm in the process of making but I want to make sure it links first.

body {
background-color: green;
}

Im assuming that you are viewing/accessing your file via desktop. Though not clearly sure if you are using localhost server or not. Here's what I think what was your file tree flow..

/115
-/css
 -- p1.css
-/p1
 -- p1.js
- index.html

Then in your HTML, it should look like this.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>CIS 115 - Project 1</title>
  <meta name="description" content="Kim Peoples - CIS 115 Project">
  <link rel="stylesheet" type="text/css" href="css/p1.css">
  <script src="p1/p1.js"> </script>
</head>

Note: Since you are initiating the index inside your 115 folder, you don't have to include 115 folder to your internal files. Just simple append the folders of your media files and CSS/JS files.

  • first you have to press ctrl + u on browser window and check css path has been coming or not? after click it css will be display properly or not ?
  • if still issue then check with inspect element in browser. press f12 in browser window.

    still issue then you can use element property in !important; in css code

Maybe try ../115/css/p1.css? Seems like your absolute path is incorrect. Here is a link to more information about absolute paths and relative paths: Absolute vs Relative Pathlinks

Hopefully this is helpful to you.

Happy Coding!

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