为什么styles.css文件不适用于页面
我将STYLES.CSS文件移至项目中的每个位置,并尝试将其链接到HTML文件中。我即使是在HTML文件所在的同一文件夹中将其移动的,HREF自动完成作品(图9上的第9行)似乎可以从HTML文件中看到styles.css,但仍然没有应用于页面。找不到原因...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现了这个问题。它是在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:
至于您的样式链接的语法,很好。您可以进入浏览器控制台(通常是击中F12),然后浏览页面观看网络选项卡,以确保浏览器找到CSS文件并加载它。
但是我认为您的问题可能在其他地方。在您显示的代码上,您的整个NAV(导航)部分在页面的头部内部(即出现 /头部出现)。那不是它所属的地方。它应该在身体部门的内部。这当然是一个问题,可能是您认为是CSS问题。
编辑:关于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.
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.