我正在使用 Kotlin to Javascript插件和 kotlinx.html构建示例应用程序的库:
fun main(args: Array<String>) {
window.onload = {
document.body!!.append.div {
a("#", classes = "red") {
+"Link"
}
}
}
}
我想将带有“红色”CSS 类的 a
链接绘制成红色。
现在我正在使用 unsage
+ raw
这样做:
document.head!!.append.style {
unsafe {
raw(".red { background: #f00; }")
}
}
如何使用 kotlinx.html DSL 创建 CSS 类?我没有找到任何与 css DSL 相关的文档。
最佳答案
您不能使用 HTML DSL 创建 CSS。在 HTML 中使用 css 有两种可能的方法。
1) 您独立创建 CSS 文件,然后按照您的建议使用 classes
。
2) 如果这对您的应用可行,则内联 CSS。
h1("h1Class") {
style = "background-color:red"
+"My header1"
}
这导致:
<h1 class="h1Class" style="background-color:red">My header1</h1>
关于javascript - 使用 kotlinx.html DSL 创建 CSS 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46504355/