【问题标题】:How is .id-name different from #id-name in CSS for a <div> tag? [duplicate]<div> 标签的 CSS 中的 .id-name 与 #id-name 有何不同? [复制]
【发布时间】:2018-06-23 23:42:03
【问题描述】:

我从 Udacity 的网站 - http://assignments.udacity-extras.appspot.com/courses/html-css/samples/style-1.html 发现了这个网络应用页面。在 CSS 部分中,提供了以下代码 -

body {
    margin: 0;
}
#content {
    max-width: 948px;
    margin: 0 auto; 
}

h1 {
    background-color: #f8981C;
    color: white;
    font-size: 48px;
    font-family: Helvetica;
    text-align: center;
    padding: 20px;
    margin: 0;

}

.row {
    display: flex;
    flex-direction: row-reverse;
    height: 100%
}

p {
    color: grey;
    font-size: 24px;
    font-family: Helvetica;
}

.image > img {
    border: 6px black dotted;
    margin-left: 20px;
}

对于以下 HTML 页面 -

<!doctype html>
<html>
  <head>
    <title>Favorite App</title>
    <link rel="stylesheet" type="text/css" href="style-1.css">
  </head>
  <body>
    <div id="content">
      <div>
        <h1 id="banner">My Favorite App</h1>
      </div>
      <div class="row">
        <div class="image"><img src="app.png">
        </div>
        <div class="description">
          <p>
          Some description here.
          </p>
        </div>
      </div>
    </div>

  </body>
</html>

现在,所有内容都在带有 id content 的标签下,而 CSS 中的样式,#content 已被使用?为什么这样 ?它与 .row 有何不同?如果我们使用 .content 而不是 #content 会发生什么?

【问题讨论】:

    标签: html css


    【解决方案1】:

    您不能使用 .content 代替 #content。 .符号用于类,# 用于 id-s。

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 2013-11-14
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多