为什么styles.css文件不适用于页面

发布于 2025-01-22 12:59:02 字数 302 浏览 3 评论 0 原文

我将STYLES.CSS文件移至项目中的每个位置,并尝试将其链接到HTML文件中。我即使是在HTML文件所在的同一文件夹中将其移动的,HREF自动完成作品(图9上的第9行)似乎可以从HTML文件中看到styles.css,但仍然没有应用于页面。找不到原因...

I'm moved styles.css file to every location in my project and tried to link it in html file. I moved it even in the same folder where html files are, href autocompletion works(line 9 on image), seems styles.css is visible from html file but still it's doesn't applied to the page. Can't find out the reason...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱桃奶球 2025-01-29 12:59:02

我发现了这个问题。它是在Express.js代码中。我没有将空间中间件用于静态文件:
app.use(express.static(path.join(__ dirname,“ public”)));
这是文档页面: https://expressjs.com/en/en/en/en/starter/statatic-static--static--static- files.html

在服务器代码中添加此之后,在我的情况下,在HTML HREF中应该是CSS文件的其余路径:

I found the problem. It was in express.js code. I didn't use spatial middleware for static files:
app.use(express.static(path.join(__dirname, "public")));
here is the documentation page:https://expressjs.com/en/starter/static-files.html

After adding this in server code, in html href should be the rest of path to css file, in my case:

对岸观火 2025-01-29 12:59:02

至于您的样式链接的语法,很好。您可以进入浏览器控制台(通常是击中F12),然后浏览页面观看网络选项卡,以确保浏览器找到CSS文件并加载它。

但是我认为您的问题可能在其他地方。在您显示的代码上,您的整个NAV(导航)部分在页面的头部内部(即出现 /头部出现)。那不是它所属的地方。它应该在身体部门的内部。这当然是一个问题,可能是您认为是CSS问题。

  • 对不起,编辑。我不知道HTML标签会被删除

编辑:关于HTML MIME类型,而不是正确的CSS MIME类型,您可以查看此链接并检查服务器配置和/或.htaccess文件以确保服务器已'hasn'被告知要解析CSS,好像是html:” StyleSheet未加载,因为其MIME类型“ Text/HTML”不是“ Text/CSS”

另外请显示CSS文件,以确认它实际上是CSS实际上不是HTML。

As far as your syntax for the style link, it's fine. You could get into a browser console (typically hit F12), then browse the page watching the network tab to make sure the browser finds the css file and loads it.

But I think your problem may be elsewhere. On the code you show, your entire nav (navigation) section is inside the head section of the page (i.e. before /head appears). That's not where it belongs. It should be inside the body section section further down. That's certainly a problem and may be what you think is a css issue.

  • sorry about the edit. I didn't know html tags would be eliminated

Edit: As regards the html MIME type instead of the correct CSS MIME type, you might look at this link and check your server configuration and/or .htaccess file to make sure the server hasn't been told to parse css as if it was html: "The stylesheet was not loaded because its MIME type, "text/html" is not "text/css"

Also please show the CSS file, to confirm it actually is css and not actually html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文