HTML文件不加载style.css文件

时间:2016-05-26 16:07:44

标签: html css

我正在做一个小网页,但现在我遇到了一个小问题。我的html文件没有加载样式文件,即使它们放在同一个文件夹中。我检查了w3schools中的css文件,它工作正常。我知道这个话题已经存在但我无法通过阅读这些来解决我的问题。我的html编码看起来像这样

<html>
 <head>
  <title>Smile's app</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
 </head>

 <body>
 <h2>Hello Dude</h2>
   <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a> 

   <blockquote>Nerds like us are allowed to be unironically enthusiastic about stuff. Nerds are allowed to love stuff - like, jump-up-and-down-in-your-chair-can't-control-yourself love it. When people call other people nerds, mostly what they're saying is "You like stuff", which is not a good insult at all. Like, "You are too enthusiastic about the miracle of human consciousness".</blockquote>
   <div class="cite">John Green</div>

   <li><a href="static/indexx.html">page2</a></li>

 </body>
</html>

css编码看起来像这样

blockquote {
  background-color: black;
  color: yellow;
  padding: 10px;
}

.cite {
  text-align: right;
  font-weight: bold;
  font-size: x-large;
}

Noe我通过Web控制台样式编辑器发现存在以下错误

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

我真的希望有人可以帮助我。

2 个答案:

答案 0 :(得分:0)

检查以下事项..(虽然你可能已经检查过它或者看起来很愚蠢)

  • 确保CSS文件与HTML

  • 位于同一目录中
  • 确保CSS文件的名称为style.css

如果所有这些都不起作用,请将CSS添加到head标记中的样式标记中,如下所示:

<html>
 <head>
  <title>Smile's app</title>
  <style>
  blockquote {
    background-color: black;
    color: yellow;
    padding: 10px;
  }

  .cite {
    text-align: right;
    font-weight: bold;
    font-size: x-large;
  }
  </style>
 </head>

 <body>
 <h2>Hello Dude</h2>
   <a href="http://www.w3schools.com/html/">Visit our HTML tutorial</a> 

   <blockquote>Nerds like us are allowed to be unironically enthusiastic about stuff. Nerds are allowed to love stuff - like, jump-up-and-down-in-your-chair-can't-control-yourself love it. When people call other people nerds, mostly what they're saying is "You like stuff", which is not a good insult at all. Like, "You are too enthusiastic about the miracle of human consciousness".</blockquote>
   <div class="cite">John Green</div>

   <li><a href="static/indexx.html">page2</a></li>

 </body>
</html>

希望这有用(虽然它很愚蠢和基本)。

注意:即使是最小,最愚蠢的基本事物也会有所作为。

答案 1 :(得分:0)

我还建议您查看文件夹结构。

您是在本地环境中开发还是在遥远的地方开发?

您使用某种Web服务器(例如Apache)还是通过file:///访问文件?

正如你所说:

  

在浏览器&#34;样式编辑器&#34;我得到以下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<title>404 Not Found</title> 
<h1>Not Found</h1> 
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p> 
     

如何进行这些更改?

在我看来,服务器无法访问css文件。 您是否检查过访问权限和文件所有者?

对不起,我现在可以推荐了所有内容,可能你已经尝试过自己的ID了,但我个人认为解决方案必须是文件系统上的somwhere,因为这两个文件看起来都是正确的