你好,我正试图从外部传递css并应用于lit-element。我在lit-element上使用了set属性,元素应该应用这个属性的样式
问题是,lit属性只将props读取为字符串,而样式对lit-element没有影响。
这里是lit代码
import { LitElement, html, css } from "lit";
export class MyElement extends LitElement {
static properties = {
classes: { type: String }
};
static styles = css`
.root {
background-color: aliceblue;
color: darkgreen;
}
`;
css;
render() {
return html`
<div class="root ${this.classes}">
<slot></slot>
<p>Hello from my template.</p>
</div>
`;
}
}
customElements.define("my-element", MyElement);
字符串
我使用vue来使用lit-element我创建了style“.myStyle”,这个类将被传递给lit-element属性,name作为类,代码如下所示
<template>
<div id="app">
<my-element classes="myStyle">
<p>slot of my element</p>
</my-element>
</div>
</template>
<script>
import "./MyElement.js";
export default {
name: "App",
};
</script>
<style scoped>
.myStyle {
display: flex;
}
my-element > .root {
color: red;
}
</style>
型
我也不能在点亮元素中使用下降样式,但我注意到下降样式只影响点亮元素的1级子元素。
是否可以将风格直接从主机传递到光元素,并将风格效果从主机传递到光元素?
- 谢谢-谢谢
1条答案
按热度按时间j0pj023g1#
其中一个解决方案可以通过使用CSS伪选择器::part()来实现
字符串
主持人的风格
型
感谢@chellappan-分享文章