【问题标题】:Why isn't my css applying?为什么我的 css 没有应用?
【发布时间】:2015-12-08 18:41:58
【问题描述】:

我尝试使用不同的编辑器和 IDE(netbeans 和 Visual Studio 代码)以及不同的浏览器(firefox 开发人员版),但是,我似乎无法将 css 表应用于主 html 文件。 样式表编辑器说 html 文件没有附加样式表 这是html文件:

<!DOCTYPE html>
<html>
    <head>
        <title>The Animal Game</title>
        <meta charset="utf-8"/>
        <link href="animalgame.css" type="text/css" rel="stylsheet" />
        <script src="animalgame.js" type="text/javascript"></script>
    </head>

    <body>
        <h1>The Animal Game</h1>
        <p>Think of an animal, then let me guess it!</p>
        <div id="container">
            <fieldset>
                <legend>Questions</legend>
                <p id="questions"></p>
            </fieldset>
            <fieldset id="answer">
                <legend>Answer</legend>
                <button id="yes">Yes</button>
                <button id="no" >No</button>
            </fieldset>
        </div>

    </body>
</html>

CSS 样式表:

body {
    font: 12pt "Century Gothic", "Helvetica", "Arial", sans-serif;
}

button {
    font-size: 20pt;
    font-weight: bold;
    margin: 15px auto;

}
#container{
    margin: auto;
    width: 520px;
}
fieldset {
    background-color: #F0F0F0;
    float: left;
    height: 150px;
    margin-right: 15px;
    text-align: center;

}
h1, p {
    text-align: center;
}
#questions {
    font-size: 16pt;
    text-align: center;
    width: 300px;
}

编辑:问题解决了!有一个错字。谢谢大家的提示

【问题讨论】:

  • 你的控制台有错误吗?
  • @George 没有显示错误
  • .html 和 .css 文件是否在同一个文件夹中?
  • 给你的想法! 1.调出fiddler,清除缓存,刷新。由于大小写问题或其他原因,请确保正在读取 css 文件而不是 404。 2. 将 CSS 转储到文件本身,并确保它按您期望的方式工作。

标签: html css


【解决方案1】:

您在rel="stylsheet" 中有错字,应该是stylesheet

【讨论】:

  • 你可以通过使用一些库,或者在你最喜欢的 IDE 中帮助你编写 HTML 样板代码的插件来避免这种简单的拼写错误;例如,SublimeText HTML BoilerPlate。让自己免于痛苦!
  • @Program-Me-Rev 我会挖掘它!我希望 Visual Studio Code 提供这样的库
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-17
  • 2013-05-06
  • 1970-01-01
  • 2013-01-18
  • 2023-01-18
  • 2018-11-21
  • 2013-01-09
相关资源
最近更新 更多