question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I override styles with incline classes with SvelteKit

See original GitHub issue

If I have something like

<h1 class="bg-green-800= bg-blue-400">Welcome to SvelteKit</h1>

The bg-green-800 class gets applied. It seems like classes are applied alphabetically, and not in the order in which they are defined.

This prevents me from doing a component that allows me to override styles, comething like this:

<script>
	let className = '';
	export { className as class };
	export let label = 'Click me!';
</script>

<button class="bg-red-500 {className}">{label}</button>

It seems to be a problem with SvelteKit, because in this playground it works ok

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alexanderniebuhrcommented, Sep 15, 2021

@opensas thanks for your report. Actually I can’t reproduce it myself. Can you please add more information or give a minimal repro.

1reaction
dansvelcommented, Sep 14, 2021

i dont understand why you want to overide it and not just like this

<script>
    export let className = 'bg-red-500';
    export let label = 'Click me!';
</script>

<button class="{className}">{label}</button>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced styling / The class directive • Svelte Tutorial
The selected class is added to the element whenever the value of the expression is truthy, and removed when it's falsy.
Read more >
Routing • Docs • SvelteKit
For this, we add a +page.js (or +page.ts , if you're TypeScript-inclined) module that exports a load function: src/routes/blog/[slug]/+page.js.
Read more >
Advanced styling / Inline styles • Svelte Tutorial
Great, now you can style the paragraph using variables that change based on your input without having to make a class for every...
Read more >
Advanced styling / The style directive • Svelte Tutorial
The style directive shares a few qualities with the class directive. You can use a shorthand when the name of the property and...
Read more >
Advanced routing • Docs • SvelteKit
Note that an optional route parameter cannot follow a rest parameter ( [...rest]/[[optional]] ), since parameters are matched 'greedily' and the optional ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found