简体   繁体   中英

CSS stylesheet not responding working with chrome

I recently started my first program (very basic) and I ran into an issue immediately!

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

Using the code above, I attempted to attach a css stylesheet. In order to make sure it wasn't just me, I copy pasted the code from an example. And to make sure that the CSS was right, I put it in a style tag in the head of my HTML file... it worked. Next, I entered the dev tools in chrome (the browser I'm using. This is on a Chromebook using the caret editor) and the css file wasn't even there!!! If you have any ideas, I really need help!

<!DOCTYPE HTML>
  <html>
    <head>
      <link rel="stylesheet" type="text/css" href="gweeble.css" />
      <title>gweeble</title>
        <meta charset="UTF-8">
        <meta name="description" content="uhhhh">
        <meta name="keywords" content="google, grooble, gweeble, bored, I'm bored, Im bored, ugh, uhhh">
        <meta name="author" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

</body>

body {
    background-color: #4542f4; }

This is usually because of a bad link in the <link> element. Are your HTML and CSS files at the same level in the file structure? If you need to go back up a level you may need to do href="./gweeble.css" Also try doing a hard refresh of your browser (hold the shift key down and click the refresh button if you're using Chrome) to clear the cache. Oh and double check the spelling of the CSS file name to ensure it is a correct match.

ANOTHER SOLUTION!!!! Here's another reason why browsers may fail to load your css file....

I've read all the responses here (and on several other sites) but was still failing to have my apparently valid css file loading into my browser (as confirmed using the inspector - right-click over code in Chrome and look at 'sources' tab).

I usually use Chrome but also tried Edge with same results - html5 code ran fine but the layout was not being rendered. Inspection showed that css file was never loaded, never mind executed.

My issue turned out to be that the html code had been copied from on-screen tutorials and pasted into Notepad ++. In the process, I ended up with the wrong speech (") marks, so my guess is that the 'meta charset="utf-8"' statement was inconsistent with the type of speechmark in the code?

Bottom line is that changing all the speechmarks by simply deleting and then re-typing resulted in a physically different shape of speechmark and working code.

Hope this was helpful....

Are you really sure you are viewing the correct HTML file? You can also check the page source (CTRL + U) to check the markup in your document.

I figured it out! My computer was set to auto put my files into a google drive section ☹️. The problem was fixed by simply moving the folder to downloads.

In case you are using node.js, express, and EJS as templating engines

I just found this error on my website and looked here. The problem I faced is if you have a CSS file in your public directory ie views(in my case)

Note: You can access your CSS file from Browser Dev tools. Using Chrome, go to Network in dev. section, and then click on CSS file. And check headers.

Make sure when you link any CSS file without any error of

  • type : "text/css"
  • Correct href = ""

Now, if you still can't access it, so the problem may be that your browser may not be accessing the file correctly. Check the path where it should be, and where you had placed.

In my case: localhost:3000/views/css/style.css throws an error

But The actual link should be: localhost:3000/css/style.css worked

So change the href accordingly, and remove extra folders coming between so that your browser can access it directly.

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