RelevantData
RelevantData

Reputation: 101

Blazor CSS isolation optional override: allow a component to use an external stylesheet if one is specified

In a Blazor component library, we can style a component in isolation using:

ComponentName.razor.css

This isolation of style is great, however, I want that to be the fallback style while allowing a user of the component library to point to a different stylesheet to use when they are using the component in their app.

How can we have both the default css isolation for a component AND optionally allow a user of the component library to override that by specifying their own external css file?

Upvotes: 0

Views: 631

Answers (1)

user6146147
user6146147

Reputation:

It's not a full solution but maybe it can point You into the right direction. You can use "style" attribute, it will override default CSS:

<button style="@newCss">some button</button>

<input @bind="newCss"/>

@code
{
    string newCss = string.Empty;
}

enter image description here

Upvotes: 1

Related Questions