by jakelazaroff · 6y ago · 0 comments
I faced the problem when trying to add layout styles to a component from the outside — basically, the parent should decide a component’s position/dimensions/etc.
FWIW, I don’t consider myself particularly good with web stuff. I’m just interested in graphics and I’ve beaten my head against it for long enough that I’ve figured out how to make some things :)
// Parent.svelte
<script>
import Child from "./Child.svelte"
</script>
<style>
.container :global(.child) {
color: red // your styles here
}
</style>
<div class="container">
<Child className="child" />
</div>
// Child.svelte
<script>
export let className
</script>
<h1 class={className}>I am styled by my parent</h1>