【问题标题】:CSS does not apply on div [closed]CSS不适用于div [关闭]
【发布时间】:2015-12-29 06:04:00
【问题描述】:

header 的 CSS 规则不适用于 Chrome 或 Firefox,但 section 可以,而且奇怪的是它们都适用于 JSFiddle。

html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="header">
    <h1>Test</h1>
</div>

<div id="section">
    <p>test</p>
</div>
</body>
</html> 

style.css:

<style>
#header {
    background-color: #f0fff0;
    color: #262626;
    text-align: center;
}
#section {
    text-align: center;
}
</style>

Fiddle

【问题讨论】:

  • 你在外部 CSS 文件中也有那些&lt;style&gt; 标签吗?为什么?
  • 为什么你的 CSS 文件有样式标签?没有 HTML 是 .css 文件。
  • 您的样式表加载正确吗? (我是说不是)。在浏览器中打开页面。查看源代码。通常,样式表链接中的“style.css”变为可点击的(在查看源代码中)。点击链接。它加载吗?还是404?
  • @qwr 你有没有看到你的网络检查器控制台来识别任何明显的错误,例如你的 .css 文件中有 HTML:&lt;style&gt; 标签无效
  • @cale_b 它以纯文本形式加载

标签: javascript html css


【解决方案1】:

HTML 在样式表中无效。

可能会删除

<style>
</style> 

在你的 .css 文件中

【讨论】:

  • 确实如此。一个快速而肮脏的测试表明,这显然是一个不可恢复的错误,在两个浏览器中。
【解决方案2】:

确保您的 html 文件和 style.css 位于同一目录中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多