css - 避免重复 CSS 样式?

标签 css

我正在使用 Html 和 JQuery。我的 styles.css 中有以下 CSS 样式。

#someTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}

#anotherTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:white;
}

在上面的 css 样式中,所有样式都相同,除了 background-color 其余所有样式都是重复的。如何避免重复并扩展 firstTable 的属性?

最佳答案

您可以使用类。它看起来像这样:

CSS:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }

html :

<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>

关于css - 避免重复 CSS 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22686380/

相关文章:

html - 需要帮助使用 HTML 字体样式

css - 如何使用 less mixin 检查宽度范围?

css - 设置 div 相对于屏幕尺寸的最小、最大和默认高度

html - 列的垂直中间对齐( Bootstrap )

javascript - 当用户滚动 jquery 时停止 ScrollTop 函数

html - 对齐留在 div 标签中的 img?

php - 在 php 中根据年龄使用特定颜色突出显示数据

css - Vue 添加元素到带有动画的列表

css - 为什么某些 CSS 属性未应用于 :visited?

javascript - 查询/CSS : Full size background image