简体   繁体   English

CSS 未从外部样式表应用

[英]CSS not being applied from external stylesheet

I have been learning how to make client-server applications recently and am following this tutorial by Traversy Media.我最近一直在学习如何制作客户端-服务器应用程序,并且正在学习 Traversy Media 的教程。 This is the Github page for the code that mine is based on. 是我所基于的代码的 Github 页。 Though I have resolved the MIME type issue that is brought up.虽然我已经解决了提出的 MIME 类型问题。

But the problem is, when I run the code, the CSS stylesheets(both the stylesheet linked to the website and the style.css file in the css folder) do not appear to be applied to the HTML page.但问题是,当我运行代码时,CSS 样式表(链接到网站的样式表和 css 文件夹中的 style.css 文件)似乎没有应用于 HTML 页面。 What happens when I run the HTML file is that the HTML page appears to be without any style, meaning that although the HTML does appear in the webpage, the HTML elements do not have any styles.当我运行 HTML 文件时,HTML 页面似乎没有任何样式,这意味着虽然 HTML 确实出现在网页中,但 HTML 元素没有任何 styles。 出现的 HTML 页面

I thought that it was simply because of an error in referencing the CSS files but I have tried to fix it by moving the CSS files around and also changing the hrefs of the link element in the HTML code and also copying the code of the CSS stylesheet from the website into "online-resource.css" but none of what I did worked.我认为这仅仅是因为引用 CSS 文件时出错,但我试图通过移动 CSS 文件并更改 HTML 代码中链接元素的 href 以及复制 CSS 样式表的代码来修复它从网站进入“online-resource.css”,但我所做的都没有用。

    <link
        rel="stylesheet"
        href="online-resource.css"
        type="stylesheet/css"
    />
    <link rel="stylesheet" href="style.css" type="stylesheet/css"/>

我如何移动文件

Anyone have any ideas?有人有主意吗? It probably doesn't have anything to do with node.js because the same thing happens when I run it independently它可能与 node.js 没有任何关系,因为当我独立运行它时会发生同样的事情

Change your type property to be text/css not stylesheet/css which is being interpreted as an invaild type and not allowing the CSS to load.将您的type属性更改为text/css而不是stylesheet/css ,后者被解释为无效类型并且不允许加载 CSS。

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

I think the css file not loading properly.我认为 css 文件没有正确加载。 Also check whether the code inside the css files are correct or not.还要检查css文件里面的代码是否正确。 Make sure you saved the file.确保您保存了文件。 It's silly, but I can personally vouch for the time when I couldn't make my site update, and I forgot to save/update the file I was viewing.这很愚蠢,但我可以亲自担保我无法更新我的网站,而且我忘记保存/更新我正在查看的文件的时间。 Make sure the stylesheet is loading.确保样式表正在加载。 In Chrome, if you right-click -> inspect element and go to the sources tab, you can see all loaded resources, including your CSS.在 Chrome 中,如果您右键单击 -> 检查元素和 go 到源选项卡,您可以看到所有加载的资源,包括您的 CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM