<!DOCTYPE html>
<html>
<head>
	<title>Class Selector</title>
	<style>
		.red {
			color: red;
		}
		.bold {
			font-weight: bold;
		}
	</style>
</head>
<body>
	<h1 class="red">This is a heading in red.</h1>
	<p class="bold">This paragraph is bold.</p>
	<p class="red bold">This paragraph is both red and bold.</p>
</body>
</html>

在上面的代码中,我们定义了两个类选择器:.red.bold,并在三个不同的元素中使用了它们。<h1> 元素的 class 属性设置为 red,因此它的文本颜色将变为红色。 <p> 元素的 class 属性设置为 bold,因此它的文本将加粗。 最后一个 <p> 元素的 class 属性设置为 red bold,因此它的文本将既加粗又变为红色。

用html写一个类选择器的代码

原文地址: https://www.cveoy.top/t/topic/bnSP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录