【问题标题】:How to specify multiple classes that can match a given selector?如何指定可以匹配给定选择器的多个类?
【发布时间】:2012-08-15 20:56:24
【问题描述】:

我正在尝试在我的 CSS(眨眼)中练习 DRY,但我一直不知道如何解决这个问题。

如何减少这种情况:

table.shipmentItemList TD.title,
table.shipmentItemList TD.author,
table.shipmentItemList TD.options {
    font-size: 1.0em;
    font-weight: normal;
}

这样的:

table.shipmentItemList TD.title, TD.author, TD.options {
    font-size: 1.0em;
    font-weight: normal;
}

或者更好的是:

table.shipmentItemList TD .title, .author, .options {
    font-size: 1.0em;
    font-weight: normal;
}

【问题讨论】:

  • 如果你想在 CSS 中做这种事情,你将不得不研究 LESS 或 SASS。由于您的代码采用标准 CSS,因此它尽善尽美。

标签: css css-selectors


【解决方案1】:

我认为在这种情况下,你只能使用 SASS:http://sass-lang.com/

标准 CSS 不允许您尝试做的事情。

【讨论】:

    【解决方案2】:

    查看LESSLESS PHP,如果您希望在服务器上执行此操作。使用 vanilla CSS 无法实现您的要求。

    您的示例如下所示:

    table.shipmentItemList {
        td {
            &.title, &.author, &.options {
                font-size: 1.0em;
                font-weight: normal;
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      看看less.js,它会让你做这样的事情:

      table.shipmentItemList{
        TD.title, TD.author, TD.options {
          font-size: 1.0em;
          font-weight: normal;
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-12
        • 2011-03-19
        • 2016-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多