-
Notifications
You must be signed in to change notification settings - Fork 182
Not able to set custom css class on Components #338
Description
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:
- Create a new Svelte project
degit sveltejs/template my-test-project
- Converted to TypeScript
node scripts/setupTypeScript.js
- Installed dependencies
npm install
- Installed sveltestrap
npm install sveltestrap
- Changed the src/App.svelte file like that:
<script>
export let name;
import { Button, Col, Row } from 'sveltestrap';
</script>
<main>
<h1>Hello {name}!</h1>
<p>Visit the <a href="https://svelte.dev/tutorial">Svelte tutorial</a> to learn how to build Svelte apps.</p>
<Row>
<Col class="hello-world">
<Button color="primary" outline>Hello World!</Button>
</Col>
</Row>
</main>
<style>
@import "https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css";
main {
text-align: center;
padding: 1em;
max-width: 240px;
margin: 0 auto;
}
h1 {
color: #ff3e00;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
}
@media (min-width: 640px) {
main {
max-width: none;
}
}
.hello-world {
background-color: #ff0000;
}
</style>
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:
(!) Plugin svelte: Unused CSS selector ".hello-world"
src/App.svelte
36: }
37:
38: .hello-world {
^
39: background-color: #ff0000;
40: }
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?