HTML Class 属性
htmlweb developmentfront end technology更新于 2025/8/29 0:12:17
HTML 中的 class 属性用于为元素设置一个或多个类名。使用指定的类名,您可以通过 CSS 对其进行处理,并将其指向样式表。
现在让我们看一个在 HTML 中实现 class 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
h2.demo {
color: orange;
background-color: black;
}
</style>
</head>
<body>
<h1>Resources</h1>
<h2 class="demo">Text Tutorials</h1>
<h2 class="demo">Video Tutorials</h1>
<h2 class="demo">Interview Questions and Answers</h1>
<h2 class="demo">Online Quiz</h1>
</body>
</html>
输出

在上面的例子中,我们为元素<h2>设置了一个类名; −
<h2 class="demo">Text Tutorials</h1> <h2 class="demo">Video Tutorials</h1>
设置样式来更新 <h2> 元素的文本和背景颜色 −
h2.demo {
color: orange;
background-color: black;
}
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

