学习CSS:为什么这段代码有效?

mac*_*ean 1 html css

我在codeschool.com上学习CSS课程,我对特定代码感到困惑.我应该编辑代码来测试CSS的特定功能,我得到了正确的答案,但我不明白为什么代码实际上有效.这是html:

<!doctype html>
<html lang="en">
  <head>
    <title>Sven's Snowshoe Emporium</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <section id="home" class="content home group">
      <aside>
        <p>Did you know that Sven's Snowshoe Emporium produces the highest quality snowshoes                        in North America? <a href="#">Find out more</a>.</p>
      </aside>
      <article>
        <h3>New Fall Styles</h3>
        <p>Be the first at your resort to sport the hot new tennis-themed snow kicks, now available in the <a href="#">store</a>.</p>
        <a class="button" href="#">See all products</a>
      </article>
    </section>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

CSS是

.home a {
  color: #c09e79;
}
article .button {
  color: #fff;
}
Run Code Online (Sandbox Code Playgroud)

我很困惑,因为在html代码中,'button'是一个类,所以我认为它会在CSS中被识别为#button,而不是.button

Ada*_*own 5

一个单词前面的一个完整停止表示它是一个类,一个散列标记表示它是一个id.

通常,Id仅在文档和类中重复使用一次

#james{
 color:#FFF;
}
.Tom{
 color:#000;
}
.Big{
 font-size:4em;
}
Run Code Online (Sandbox Code Playgroud)

第一个只能用'id ="James"'加入,而第二个用'class ="Tom"加入

你可以在一个对象上有多个类但只有一个id,以添加一个额外的类,你只需要放一个空格.

class="Tom Big"
Run Code Online (Sandbox Code Playgroud)