来自父组件的样式插槽元素
Style slot elements from parent component
我想让一个组件将某些样式应用到在 slot 属性.
中传递的元素
示例:
Component.svelte
<style>
h1 { color: blue }
p { color: grey }
</style>
<div>
<slot></slot>
</div>
然后,我们将包含元素
<script>
include Component from './component.svelte'
</script>
<Component>
<h1>My component</h1>
<p>Lorum Ipsum</p>
</Component>
结果将是:
h1 { color: blue }
p { color: grey }
<div>
<h1>My component</h1>
<p>Lorum Ipsum</p>
</div>
我想让一个组件将某些样式应用到在 slot 属性.
中传递的元素示例:
Component.svelte
<style>
h1 { color: blue }
p { color: grey }
</style>
<div>
<slot></slot>
</div>
然后,我们将包含元素
<script>
include Component from './component.svelte'
</script>
<Component>
<h1>My component</h1>
<p>Lorum Ipsum</p>
</Component>
结果将是:
h1 { color: blue }
p { color: grey }
<div>
<h1>My component</h1>
<p>Lorum Ipsum</p>
</div>