-1 html css coding-style
我是编程新手,我不明白为什么我们应该在 HTML 中使用多个类。我的意思是,无论如何,即使它是一个类或多个类,所有 CSS 样式都将仅应用于相同的内容/文本,那么当单个类执行相同的操作时,多个类有什么用呢?
小智 5
您使用多个类来保持代码干燥(不要重复自己),例如,假设您有两个按钮,一个蓝色的主按钮和一个红色的辅助按钮。
.red-button {
background-color: red;
border-radius: 3px;
color: #fff;
padding: 10px;
}
.blue-button {
background-color: blue;
border-radius: 3px;
color: #fff;
padding: 10px;
}
Run Code Online (Sandbox Code Playgroud)
这里你有重复的CSS。
对于多个课程,你可以做类似的事情
.button {
border-radius: 3px;
color: #fff;
padding: 10px;
}
.button.red {
background-color: red;
}
.button.blue {
background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)