<!DOCTYPE html>
<html>
<head>
<title>HTML中class的用法</title>
<style>
/* 定义一个样式类 */
.highlight {
background-color: yellow;
font-weight: bold;
}
</style>
</head>
<body>
<!-- 使用class属性为元素应用样式 -->
<p class="highlight">这是一个使用了class属性的段落。</p>
<p>这是一个没有使用class属性的段落。</p>
<!-- 可以为多个元素应用同一个class -->
<div class="highlight">这是一个使用了class属性的div。</div>
<span class="highlight">这是一个使用了class属性的span。</span>
<!-- 一个元素可以有多个class -->
<p class="highlight important">这是一个同时使用了两个class的段落。</p>
<style>
/* 定义另一个样式类 */
.important {
color: red;
}
</style>
</body>
</html>
<style>标签中,我们定义了一个名为.highlight的样式类,它设置了背景颜色为黄色,并加粗字体。class="highlight",我们可以将定义好的样式应用到这些元素上。<p>、<div>、<span>)可以共享同一个class,从而应用相同的样式。class="highlight important",这样可以同时应用多个样式的组合。上一篇:html居中对齐代码怎么写
下一篇:html th
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站