如何在ScalaTags中写tr:nth-​​child(偶数)?

时间:2016-12-10 18:20:58

标签: css scala scalatags

让我们有这个简单的CSS:

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

如何在ScalaTags中编写它?

我希望看到tr.nthChild之类的内容,但只有firstChildlastChildonlyChild

1 个答案:

答案 0 :(得分: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"
  )
}