【问题标题】:How to write tr:nth-child(even) in ScalaTags?如何在 ScalaTags 中编写 tr:nth-child(even)?
【发布时间】:2017-03-22 09:06:45
【问题描述】:

让我们拥有这个简单的 css:

tr:nth-child(even) {
    background-color: red;
}

如何在 ScalaTags 中编写?

我期待看到像tr.nthChild 这样的东西,但只有firstChildlastChildonlyChild

【问题讨论】:

    标签: css scala scalatags


    【解决方案1】:

    doesn't look like ScalaTags provides it

    我们可以自己写:

    object Foo extends StyleSheet {
    
      implicit class CreatorWrapper(val creator: Creator) extends AnyVal {
        def nthChildEven: Creator = nthChild("even")
        def nthChild(arg: String): Creator = creator.pseudoExtend(s"nth-child($arg)")
      }
    
      val foo = cls.nthChildEven(
        backgroundColor := "red"
      )
    }
    

    或者如果你不想要隐式类:

    object Foo extends StyleSheet {
      val foo = cls.pseudoExtend(s"nth-child(even)")(
        backgroundColor := "red"
      )
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 2014-12-17
      • 1970-01-01
      相关资源
      最近更新 更多