样式表的相对链接在本地机器上不起作用,在线工作。为什么是这样?

Eri*_*k V 5 html css stylesheet rel

我正在尝试将我的样式表 (styles.css) 链接到 index.html。当我使用 Chrome 的 Sublime Text 构建功能执行此操作时,HTML 显示正常,但未链接到样式表(文本不是蓝色)。当我将此完全相同的代码(在相同的文件夹结构中)上传到 BitBalloon 时,该链接有效。为什么会这样,我如何使链接在两种情况下都能正常工作?

索引.html:

<!DOCTYPE HTML>
<html>
<head>
    <title>I think I'm doing this right!</title>
    <link rel="stylesheet" type="text/css" href="/css/styles.css" />
</heaod>
<body>
    <div class="jumbotron">
      <div class="container">
        <h1>CareerFoundry Template</h1>
        <p style="background-color: red;">This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more &nbsp;&amp;&nbsp; unique.</p>
        <p><a class="btn btn-primary btn-lg" role="button">Learn more &raquo;</a></p>
      </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

样式.css:

body {color:blue;}

在 BitBalloon 上使用 HTML 和 CSS

Ale*_*x L 4

在标准设置中,您的在线根目录设置为 public_html(或 www)。

第一部分:

/css/styles.css

告诉我们要查看项目的根目录“/”并从那里开始。在您的计算机上,它使用“/”作为计算机的根目录。

如果 css 文件夹与包含 html 文件的目录相同,则仅使用“css/styles.css”可能会起作用。

否则,您可以运行本地 Web 服务器(例如WAMP),它允许您以 root 身份在本地计算机上拥有一个 public_html 文件夹。