Skip to content

Styling child and nested components in CSS #5092

@TheComputerM

Description

@TheComputerM

The problem is that I want to style components using CSS in the style tag, it prevents me from using the component to its fullest potential and making components easily customizable.

The solution could be:

Component.svelte

h1 {
  color: red;
}
<div style>
    <h1>Hello There</h1>
</div>

App.svelte

import Component from "./Component.svelte";
Component h1 {
    color: blue
}
<Component />

Current solution

Add a style prop to the component.

Component.svelte

export let style;
<div>
    <h1 {style}>Hello There</h1>
</div>

This problem is not too important, but definitely helps when working with UI libraries for making minor changes without changing much code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions