最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

html中规定元素的类名的属性class

来源:懂视网 责编:小采 时间:2020-11-27 15:28:12
文档

html中规定元素的类名的属性class

html中规定元素的类名的属性class:实例在 HTML 文档中使用 class 属性:<html> <head> <style type="text/css"> h1.intro {color:blue;} p.important {color:green;} </style> </head> <b
推荐度:
导读html中规定元素的类名的属性class:实例在 HTML 文档中使用 class 属性:<html> <head> <style type="text/css"> h1.intro {color:blue;} p.important {color:green;} </style> </head> <b

实例

在 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 支持这种做法。

浏览器支持

W3C: "W3C" 列指示 W3C 的 HTML/XHTML 推荐标准中是否定义了该属性。

IEFirefoxOperaSafariW3C
YESYESYESYESYES

语法

<element class="value">

属性值

描述
classname规定元素的类的名称。如需为一个元素规定多个类,用空格分隔类名。

示例

<div class="dreamdu1">连接div标签与dreamdu1样式<div>
<div class="dreamdu12px dreamdublack dreamdubold">使用空格分开多个样式连接div标签<div>
div.dreamdu12px{	
font-size: 12px;}
div.dreamdublack{	
color: black;}
div.dreamdubold{	
font-weight: bold;}

可以使用多个classname,但是要使用空格分开

文档

html中规定元素的类名的属性class

html中规定元素的类名的属性class:实例在 HTML 文档中使用 class 属性:<html> <head> <style type="text/css"> h1.intro {color:blue;} p.important {color:green;} </style> </head> <b
推荐度:
标签: html html中 属性
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top