简体   繁体   English

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

[英]Why styles.css file doesn't apply to the page

I'm moved styles.css file to every location in my project and tried to link it in html file.我将 styles.css 文件移动到项目中的每个位置,并尝试将其链接到 html 文件中。 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.我什至将它移动到 html 文件所在的同一文件夹中,href 自动完成工作(图像上的第 9 行),似乎 styles.css 从 html 文件中可见,但它仍然不适用于页面。 Can't find out the reason...找不到原因...

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.您可以进入浏览器控制台(通常按 F12),然后浏览查看 .network 选项卡的页面,以确保浏览器找到 css 文件并加载它。

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 (ie before /head appears).在您显示的代码中,您的整个导航(导航)部分位于页面的头部部分(即在 /head 出现之前)。 That's not where it belongs.那不是它所属的地方。 It should be inside the body section section further down.它应该在 body 部分的内部。 That's certainly a problem and may be what you think is a css issue.这肯定是个问题,可能是您认为的 css 问题。

  • sorry about the edit.对不起编辑。 I didn't know html tags would be eliminated我不知道 html 标签会被淘汰

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"编辑:关于 html MIME 类型而不是正确的 CSS MIME 类型,您可以查看此链接并检查您的服务器配置和/或 .htaccess 文件以确保服务器没有被告知解析 css 就好像它是 html : “样式表未加载,因为它的 MIME 类型“text/html”不是“text/css”

Also please show the CSS file, to confirm it actually is css and not actually html.另外请出示 CSS 文件,以确认它实际上是 css 而不是 html。

I found the problem.我发现了问题。 It was in express.js code.它在 express.js 代码中。 I didn't use spatial middleware for static files: app.use(express.static(path.join(__dirname, "public")));我没有为 static 个文件使用空间中间件: app.use(express.static(path.join(__dirname, "public"))); here is the documentation page: https://expressjs.com/en/starter/static-files.html这是文档页面: 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:在服务器代码中添加后,html href 应该是 css 文件路径的 rest,在我的例子中:

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

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