You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When having code injected into a component via {@html expression}, the rendered HTML does not apply all of the component's CSS styles. In this example, only the first is properly styled:
<style>
a { color: red; }
</style>
<script>
let messageHTML = 'Here is an HTML expression without a styled <a href="/">link</a> :('
</script>
<div class="htmlText">
Here is a normal styled <a href="/">link</a>
</div>
<div class="htmlText">
{@html messageHTML}
</div>
This is expected. Svelte can only scope styles that it can statically analyze at compile time. If you need certain styles to be unscoped, you can wrap parts of the selector in :global( ).
A style like div.htmlText :global(a) { color: red; } would scope the div.htmlText part of the selector to this component, but would match anya inside that, regardless of whether it's something Svelte can see while compiling.
When having code injected into a component via
{@html expression}
, the rendered HTML does not apply all of the component's CSS styles. In this example, only the first is properly styled:Live reproduction: https://svelte.dev/repl/c1976e67d38d453dae297e90663c9ece?version=3.4.4
The text was updated successfully, but these errors were encountered: