【问题标题】:Why isn't CSS being ran on HTML file?为什么 CSS 不在 HTML 文件上运行?
【发布时间】:2017-06-21 15:46:33
【问题描述】:

正在做一个项目,我目前有这个:

<!DOCTYPE html>
  <html>
    <head>
       <title>Jams</title>
       <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Open+Sans:400,800,600,700,300">
       <link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
       <link rel="stylesheet" type="text/css" href="styles/normalize.css/normalize.css">
       <link rel="stylesheet" type="text/css" href="styles/main.css">
    </head>

我的目录是

jams  
|---- musicplayer[index.html]  
|---- styles  
|     |---- main.css  
|     |---- normalize.css(folder)  
|     |     |---- normalize.css(file)

抱歉,目录可能看起来令人困惑,但它主要指出 jams 是父文件夹,文件夹的其余部分在里面,括号是文件夹内的文件。唯一的例外是 normalize.css,它是样式内的文件夹,而 normalize.css 文件夹内是 normalize.css 文件。

【问题讨论】:

  • 您是否尝试过在前面加上一个/ 相对于网站根目录的含义?
  • normalize.css 文件夹在样式文件夹下?
  • 根据您对结构的描述,您拥有的代码应该可以正常工作。使用浏览器中的开发人员工具。检查控制台是否有错误。检查“网络”选项卡以查看请求实际返回的内容(例如,您可能遇到权限错误)
  • @s.k.Soni 是的

标签: html css


【解决方案1】:

在检查器窗口中,右键单击样式表链接并选择open in new tab

从那里您将能够看到页面试图从中提取 CSS 的完整 URL。这应该让您更好地了解需要做什么来修复它。

另外,我会尝试将./ 添加到href 的开头。即href="./styles/main.css"

【讨论】:

    【解决方案2】:

    编辑行

    href="styles/normalize.css/normalize.css 和 href="styles/main.css

    将这两行替换为

    href="./styles/normalize.css/normalize.css" 和 href="./styles/main.css"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2014-09-07
      • 2013-05-21
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      相关资源
      最近更新 更多