CSS 样式表未链接到我的 html 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20875452/
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 00:15:55  来源:igfitidea点击:

CSS stylesheet not linking to my html page

htmlcss

提问by James Dorfman

I have a problem where my css does not affect my html. I made a fiddle hereIt worked when I wasn't trying to connect an external stylesheet and used style tags, Thanks in advance to anyone who can help.

我有一个问题,我的 css 不影响我的 html。我在这里做了一个小提琴 当我没有尝试连接外部样式表并使用样式标签时它起作用了,在此先感谢任何可以提供帮助的人。

btw i tried

顺便说一句,我试过了

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

and it did not work.

它没有用。

回答by BuddhistBeast

Make sure you are linking it in your 'head' section of the HTML such as this:

确保将它链接到 HTML 的“头部”部分,例如:

<head>
    <link href="index.css" type="text/css" rel="stylesheet" /> 
</head>

Also be sure to close the tag and that the style sheet you are linking is named 'index.css'

还要确保关闭标记,并且您正在链接的样式表名为“index.css”

Edit:

编辑:

HTML is split up into two main section tags: body and head. In a normal HTML page, the structure is like so:

HTML 分为两个主要部分标签:body 和 head。在一个普通的 HTML 页面中,结构是这样的:

<html>
    <head>
    </head>
    <body>
    </body>
</html>

The code I referenced at the beginning of this answer should be placed into the head section of the HTML page.

我在这个答案开头引用的代码应该放在 HTML 页面的 head 部分。

回答by David Sawyer

The fact that you are linking to simply index.cssworries me. Is index.cssin your site root? If so, specify that:

你链接到的事实让我很index.css担心。是否index.css在您的网站根目录中?如果是,请说明:

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

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

回答by iamspialeo

As stated also by BuddhistBeast, check to make sure it's in between the head tags:

正如BuddhaBeast 所述,请检查以确保它位于头部标签之间:

<head>
<link href="index.css" type="text/css" rel="stylesheet" /> 
</head>

Also check that you are referencing it correctly. If it is all in one folder, then

还要检查您是否正确引用了它。如果都在一个文件夹中,那么

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

is correct.

是正确的。

If it's in its own folder, named "css" for example, it should be written as:

如果它在它自己的文件夹中,例如名为“css”,它应该写为:

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

回答by James Dorfman

You put #buttoninstead of input, #buttonin the css.

你把#button而不是input, #button在css中。