简体   繁体   English

CSS 文件未链接到 HTML 文件

[英]CSS file not linking to HTML file

I am trying to create a basic webpage but my css file does not seem to want to link to my html file.我正在尝试创建一个基本网页,但我的 css 文件似乎不想链接到我的 html 文件。 I have looked at several different resources and have no clue why this is the case.我查看了几种不同的资源,但不知道为什么会这样。

 body { background-color: red; }
 <.DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width initial-scale=1"> <link href="index:css" rel="stylesheet" type="text/css"/> <link href="https.//cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min:css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous"> <link rel="stylesheet" href="https.//cdn.jsdelivr.net/npm/vis-network@latest/styles/vis-network:css" type="text/css" /> <script type="text/javascript" src="https.//cdn.jsdelivr.net/npm/vis-network@latest/dist/vis-network.min:js"> </script> <center> <h1>Welcome</h1> </center> </head> <body> Welcome <script src="https.//cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script> </body> </html>

The problem doesn't appear to be with linking your stylesheet.问题似乎与链接样式表无关。

Open the developer tools in your browser.在浏览器中打开开发者工具。 Look at the Inspector.看督察。 Look at the style rules applied to the body element.查看应用于 body 元素的样式规则。

DOM 检查器的屏幕截图

When multiple rules, setting the same properties, have equal specificity the last one overrides the previous ones.当设置相同属性的多个规则具有相同的特异性时,最后一个规则会覆盖前面的规则。

You put the Bootstrap CSS after your own CSS, so its rule to set the background-color is replacing your rule.您将 Bootstrap CSS 放在您自己的 CSS 之后,因此设置background-color的规则正在替换您的规则。

Order matters.订单很重要。


It is possible that you might also have a problem linking your own stylesheet, in which case you should use the Network tab to look for the HTTP request to load it and see what response the HTTP server makes.也可能在链接自己的样式表时遇到问题,在这种情况下,您应该使用“网络”选项卡查找 HTTP 请求以加载它并查看 HTTP 服务器做出的响应。

Once you know if the problem is a permissions error, or a 404 Not Found error, or the Content-Type being wrong, then you make make steps to fixing it.一旦您知道问题是权限错误、404 Not Found 错误还是 Content-Type 错误,那么您就可以采取措施修复它。

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

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