Class 与 ID 的差异
同一个类名可以由多个 HTML 元素使用,而一个 id 名称只能由页面中的一个 HTML 元素使用:
实例
/* 设置 id 为 "myHeader" 的元素的样式 */
#myHeader {
background-color: lightblue;
color: black;
padding: 40px;
text-align: center;
}
/* 设置类名为 "city" 的所有元素的样式 */
.city {
background-color: tomato;
color: white;
padding: 10px;
}
My Cities
London
London is the capital of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
提示:请在我们的 CSS 教程 中学习更多 CSS 知识。