Kir*_*ill 1 javascript css dsl kotlin kotlinx-html
我正在使用Kotlin 到 Javascript插件和kotlinx.html库来构建示例应用程序:
fun main(args: Array<String>) {
window.onload = {
document.body!!.append.div {
a("#", classes = "red") {
+"Link"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想a将带有“红色”CSS 类的链接绘制为红色。
现在我使用unsage+raw来做到这一点:
document.head!!.append.style {
unsafe {
raw(".red { background: #f00; }")
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用 kotlinx.html DSL 创建 CSS 类?我没有找到任何与 css DSL 相关的文档。
您不能使用 HTML DSL 来创建 CSS。在 HTML 中使用 css 有两种可能的方法。
1) 您独立创建 CSS 文件,然后classes按照您的建议使用。2) 如果这对您的应用程序可行,则内联 CSS。
h1("h1Class") {
style = "background-color:red"
+"My header1"
}
Run Code Online (Sandbox Code Playgroud)
这导致:
<h1 class="h1Class" style="background-color:red">My header1</h1>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1753 次 |
| 最近记录: |