
为了更快地创建CSS,我们可以给单个HTML元素赋予多个类,并分别为每个类设置样式。这种方法允许我们管理样式应用的冗余。我们可以将通用样式应用于许多类,而将特定类别的样式应用于特定类别。
语法
Example
在下面的示例中,我们使用class“Varma”的样式来应用于两个段落,而第二个段落应用了secondclass varma1的样式。
.varma { font-size: larger; margin-bottom: 35px; background-color: lightgreen; } .varma1 { color: red; } Hello Everyone.
Welcome to Turorialspoint.
执行上述脚本后将生成结果。它是文本“欢迎来到tutorialspoint”与两个CSS样式以及文本“大家好”与单个CSS样式的组合。
Example: Using javascript
In the following example we are adding two style to an single text by declaring the .bg-blue style and .text-white style.
.bg-blue { background-color: lightgreen; } .text-white { color: red; } Welcome To Tutorialspoint const box = document.getElementById('varma'); box.classList.add('bg-blue', 'text-white');
在执行时,脚本生成一个应用了两个CSS样式的文本输出:“欢迎来到教程点”。
立即学习“前端免费学习笔记(深入)”;
以上就是在HTML中为一个元素使用多个CSS类的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1551785.html
微信扫一扫
支付宝扫一扫