css - 如何排序和组合此 css 规则,以免重复太多?

标签 css minify

这个 css 规则有效,但是天啊,这么多行重复规则,我怎样才能最小化它?我尝试了一些网站来减少它,但我认为人类可以做得更好。请举例说明,谢谢。

HTML 示例(各个区域变化,看起来都是这样)

<span class="term-links">Region: <a href="/region/japan/"><span class="japan">Japan</span></a></span>

CSS

 .term-links .usa {
        display: inline-block;
        width: 16px;
        height: 11px;
        background: url('/img/usa.gif');
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
    }
    .term-links .japan {
        display: inline-block;
        width: 16px;
        height: 11px;
        background: url('/img/japan.gif');
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
    }
    .term-links .europe {
        display: inline-block;
        width: 16px;
        height: 11px;
        background: url('/img/europe.gif');
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
    }
    .term-links .korea {
        display: inline-block;
        width: 16px;
        height: 11px;
        background: url('/img/korea.gif');
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
    }
    .term-links .china {
        display: inline-block;
        width: 16px;
        height: 11px;
        background: url('/img/china.gif');
        text-indent: 100%;
        white-space: nowrap;
        overflow: hidden;
    }

最佳答案

以此为起点进行重构:

.term-links span
{
    display: inline-block;
    width: 16px;
    height: 11px;
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
}
.term-links .usa {
    background: url('/img/usa.gif');
}
.term-links .japan {
    background: url('/img/japan.gif');
}

同一元素有多个规则是完全可以接受的。

关于css - 如何排序和组合此 css 规则,以免重复太多?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732566/

相关文章:

html - 水平对齐位于另一个表中的两个表

CSS 过渡 : Shrink height of div whose height is determined by its content

CSS 图像 Sprite 在样式表中不起作用,而作为内联代码工作

javascript - 在 ASP.NET MVC 中将 javascript 和 css 文件与 Rejuicer 结合

css - 合并 2 个大型 CSS 文件的有效方法

javascript - 缩小对象属性的解决方案?

javascript - 无法在 Chrome 上看到控制台错误

css - 翻转时图像倾斜 - 无法弄清楚为什么

Grep 并忽略缩小的 javascript

javascript - 使用 node.js 在生产模式下缩小脚本/CSS