【发布时间】:2018-04-19 14:32:56
【问题描述】:
我无法将我的 css 样式表链接到我的 html 文件。我相信所有内容的格式都正确,当我在 finder 中打开 html 文件时,它会给出正确的输出,但是当我运行在本地打开它的 webapp 时它不起作用。我正在使用 sublime 进行编辑。
这是我的 index.html 文件和我的 css 文件的一部分。
index.html:
<html>
<head>
<title>Attack On Purdue Login</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="init_div">
<h1>ATTTACK ON PURDUE</h1>
<div>
<p style="display: inline">Username: </p>
<input type="username">
</div>
<div>
<p style="display: inline">Password: </p>
<input type="password">
</div>
<button onclick="login()">Login</button>
</div>
...
styles.css:
#init_div {
width:800px;
height:600px;
background-color:red;
}
编辑: 实际上,我认为这与我如何运行它有关。我正在使用节点来运行我的 index.js 文件并快速打开 index.html
这是link 和我的文件路径:
【问题讨论】:
-
例如您的网站位于
localhost/test/然后尝试访问localhost/test/styles.css,是否加载了样式? -
应该可以。你确定你的
styles.css和你index.html在同一个目录吗? -
styles.css 和 index.html 是否在同一个目录下。如果没有,您将需要提供 styles.css 的相对路径
-
是的,它们在同一个目录中
-
应该可以工作,仔细检查文件名。