HTML 不会链接到 Visual Studio Code 中的 CSS 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39863458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:53:38  来源:igfitidea点击:

HTML wont link to CSS file in Visual Studio Code

htmlcssvisual-studio-code

提问by Chris Cundari

I am trying to link my css formatting to an HTML document.

我正在尝试将我的 css 格式链接到 HTML 文档。

enter image description here

在此处输入图片说明

As you can see, my CSS is link is

如您所见,我的 CSS 链接是

<link rel="stylesheet" href="css/style.css" />

And my CSS file is titled style.css in a folder called css. Why is it not linking?

我的 CSS 文件在名为 css 的文件夹中名为 style.css。为什么不链接?

回答by Daniel

I would add the attribute type and value "text/css" Your link tag would end up like this:

我会添加属性类型和值 "text/css" 你的链接标签最终会是这样的:

<link rel="stylesheet" href="css/style.css" type="text/css"

回答by vaibhav pawar

If you are loading static file into html then you should mention in html code that you are loading static files explicitly. See the below code:

如果您要将静态文件加载到 html 中,那么您应该在 html 代码中提到您正在显式加载静态文件。请参阅以下代码:

{% load staticfiles %}
<html>

<head lang="en">

    <title>SuperStore DashBoard</title>
    <meta charset="utf-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="{% static 'css/superstore.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.css' %}" />
    <script src="{% static 'js/bundle.js' %}"></script>
    <script src="{% static 'js/superstore.js' %}"></script>

</head>
<body>
</body>

</html>

These two are css static files

这两个是css静态文件

href="{% static 'css/superstore.css' %}"
href="{% static 'css/bootstrap.css' %}" 

These are static javascript files

这些是静态 javascript 文件

src="{% static 'js/bundle.js' %}"
src="{% static 'js/superstore.js' %}"

css and js are folder name in visual studio code.

css 和 js 是 Visual Studio 代码中的文件夹名称。

{% load staticfiles %}

You have to mention static files before the start of your html code.

您必须在 html 代码开始之前提及静态文件。

回答by Div111

If you have any project structure with seperate subfolders for ".html" file, ".css" file, ".js" file etc and you are trying to link your ".html" file to ".css" file then:

如果您的任何项目结构具有“.html”文件、“.css”文件、“.js”文件等的单独子文件夹,并且您尝试将“.html”文件链接到“.css”文件,则:

  • In html file, give the path of your ".css" file in href = "../folderName/filename.css"

    such as: "<link rel="stylesheet" href="../css/main.css"/>"

  • 在 html 文件中,在href = "../folderName/filename.css" 中给出“.css”文件的路径

    例如:“ <link rel="stylesheet" href="../css/main.css"/>

回答by Johannes

The question is: Where is your html file? Obviously not in the root folder, but probably in another sub folder. Try this

问题是:你的html文件在哪里?显然不在根文件夹中,而可能在另一个子文件夹中。尝试这个

<link rel="stylesheet" href="../css/style.css" />

This navigates one level up and then into the cssfolder.

这会向上导航一级,然后进入css文件夹。