一、实例
在 HTML 文档中使用 class 属性:
<html>
<head>
<style type="text/css">
h1.intro {color:blue;}
p.important {color:green;}
</style>
</head>
<body>
<h1 class="intro">Header 1</h1>
<p>A paragraph.</p>
<p class="important">Note that this is an important paragraph.</p>
</body>
</html>
二、定义和用法
class 属性规定元素的类名(classname)。
class 属性大多数时候用于指向样式表中的类(class)。不过,也可以利用它通过 JavaScript 来改变带有指定 class 的 HTML 元素。
三、提示和注释
注释:class 属性不能在以下 HTML 元素中使用:base, head, html, meta, param, script, style 以及 title。
提示:可以给 HTML 元素赋予多个 class,用空格分隔类名。例如:<span class="left_menu important">。这么做可以把若干个 CSS 类合并到一个 HTML 元素。
提示:类名不能以数字开头!只有 Internet Explorer 支持这种做法。