在 HTML 文档中使用 class 属性:
</>code
- <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 支持这种做法。
W3C: "W3C" 列指示 W3C 的 HTML/XHTML 推荐标准中是否定义了该属性。
IE | Firefox | Opera | Safari | W3C |
---|---|---|---|---|
YES | YES | YES | YES | YES |
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛
Powered by 365建站网 RSS地图 HTML地图
copyright © 2013-2024 版权所有 鄂ICP备17013400号