HTML链接与外部CSS无法正常工作

时间:2015-06-10 18:29:16

标签: html css web

当我尝试将以下代码链接到我的CSS文件时,它不起作用。

response.write

style.css内容:

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" type="text/css" rel="stylesheet"/>
    </head>
    <body>
        <div class="body"
        </div>
    <body>
</html>

在HTML文件中,我以粗体显示的以下内容在记事本++中用红线加下划线:
&lt; -link href =“style。 css ”type =“text / css ”rel =“ stylesheet ”/&gt; *请注意链接href = 中的“ - ”是出于演示目的。

似乎不起作用。背景颜色保持白色。有什么帮助吗?

5 个答案:

答案 0 :(得分:1)

在div中添加一些内容。

并像这样关闭div

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" type="text/css" rel="stylesheet"/>
      <style>
        body {
          background-color: blue;
          }
        </style>
    </head>
    <body>
        <div class="body"> <!-- please check I closed this tag -->
        </div>
    <body>
</html>

答案 1 :(得分:0)

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" type="text/css" rel="stylesheet"/>
        <style>
          body {
            background: blue;
          }
    </head>
    <body>
        <div class="body">
        </div>
    </body>
</html>

你没有关闭你的标签以及身体。 BTW您可以将主体设置为背景颜色而不是其中的部分,因为它没有设置任何宽度和高度。

<div class="body">
</div>
</body> <!-- Close body -->

答案 2 :(得分:-1)

请检查CSS文件的路径。

或者你可以使用样式标记放置内部CSS。

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" type="text/css" rel="stylesheet"/>
      <style>
        body {
          background-color: blue;
          }
        </style>
    </head>
    <body>
        <div class="body">
        </div>
    <body>
</html>

答案 3 :(得分:-1)

1 - 确保您的style.css不在服务器上的另一个目录中

2 - 你不需要为已经优先考虑的身体打电话。

使用此选项并删除class = body div :)

body {
background-color: #000000;}

答案 4 :(得分:-2)

你可以把它作为

body {
background-color: blue;
}

在样式表中,也不需要

<div class="body">
</div>

你没有正确关闭标签!

您也可以使用id来设置div [{1}}

的样式

在css中它将是

div id = body