Skip to content

Why is this line text red and not blue? #3061

Answered by bill-kerr
frederikhors asked this question in Q&A
Discussion options

You must be logged in to vote

@frederikhors

The reason the text is red is because text-red-500 is defined later in the stylesheet, and because both those classes have the same specificity and target the same property, the class that is defined last prevails. This is not a Svelte-specific issue...you'll run into this whenever you use atomic classes like this and need to override default styles you've applied.

With SvelteKit and TailwindCSS, I usually deal with it like this:

<script lang="ts">
	let klass = '';
	export { klass as class };
</script>

<span class={`defaults ${klass}`}>
	<slot />
</span>

<style lang="postcss">
	.defaults {
		@apply text-red-500;
	}
</style>

There may be a more elegant way, but I've spent …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@frederikhors
Comment options

@munaja
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by dummdidumm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants