-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to set custom css class on Components #338
Comments
Hi, this is unfortunately a svelte limitation. I don't have an issue # handy, but the scoped styles only apply to Dom elements. To do what you want here you'd have to add: :global(.hello-world) {
...
} Or move that css to your separate stylesheet. |
Here's an rfc issue that links to many other issues and discussion of this: sveltejs/rfcs#22 Good description on why it's not supported: |
Wow, very quick reply. Thank you! That makes sense to me. Obviously, I'm fairly new to svelte and wasn't aware of these limitations. This just seemed like such a common problem to me (and it kinda is, as the discussion in the linked PR suggests :) ). Closing this, since this isn't an issue with sveltestrap. Thanks for your help! |
Yes it's a bit annoying, but I understand the reasoning. |
I'm new to Svelte and found this gh-issue after running into this little quirk. There is almost a solution, here: sveltejs/rfcs#13 (comment) But I can't quite get it to override bootstrap styles correctly. Maybe someone else can point the way? If I put the bundle.css after bootstrap's css in my using devtools it sort of works, is there a way to integrate sveltestrap such that this happens? Not totally sure, but do you think it's worth lobbying the svelte project to make this path a little closer to default? This workflow of adding classes to override component library styles is super common, and so this is quite the pitfall when starting to use svelte and integrate component libraries like you would with eg react and react-bootstrap. Assuming the preprocessor method above works, is there any downside to using it? If not, it would seem there isn't truly a limitation with svelte, but just that the framework could make this path a little smoother out of the box. |
Hi there,
I'm wondering how to style a single sveltestrap component. I found other issues with similar problems that styled the components using
:global
. This obviously styles all the components. But only applying a style to a single component seems so obvious to me, that I'm currently refusing to believe that this isn't possible.Here's a reproducable example:
degit sveltejs/template my-test-project
node scripts/setupTypeScript.js
npm install
npm install sveltestrap
What I expected to happen?
The column component would pick up my hello-world class and have a red background
What actually happened?
I get a compile warning:
The resulting HTML actually has a "hello-world" class, but not a special svelte class as usual components.
If I use the default bootstrap class, i.e. replace
<Col class="hello-world">
with<div class="col hello-world">
everything works as expected.Is it really not possible like that or am I missing something here?
The text was updated successfully, but these errors were encountered: