Skip to content

Commit 6fdc11b

Browse files
authored
docs: svelte global CSS for use in overrides (#235)
Add documentation showing how global styles can be used for targeted style overrides.
1 parent 5ae691e commit 6fdc11b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

apps/docs/src/pages/theming/override.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,38 @@ Various (but not all) components support changing their root elements with the `
101101
102102
<Box root="p">I was a div but now I'm a paragraph tag!</Box>
103103
```
104+
## Overriding using Svelte's `<style global>` functionality
105+
106+
Svelte's global CSS styling feature can be used to override and enhance styles for SvelteUI components and their internal DOM elements.
107+
108+
Given a component with a known structure, like `AppShell`, which contains a `div.app-shell` element used as a container, the following component would work:
109+
110+
```svelte
111+
<AppShell height="100%" class="app-shell h-full flex flex-col">
112+
<YourHeaderComponent slot="header" {user} />
113+
114+
<!-- Content -->
115+
<slot class="container flex-grow" />
116+
117+
<!-- Footer -->
118+
<YourFooterComponent slot="footer" />
119+
</AppShell>
120+
121+
<style global>
122+
/* Target the first inner wrapper container inside the AppShell */
123+
.app-shell > div {
124+
height: 100%;
125+
display: flex;
126+
flex-direction: column;
127+
}
128+
129+
/* Target the wrapper div *for content* which is two layers down inside the AppShell */
130+
.app-shell > div > div.body {
131+
flex-grow: 1;
132+
}
133+
</style>
134+
```
135+
136+
The [TailwindCSS][tailwindcss]-flavored example code above makes targeted changes to the implicit inner `<div>` contained in [`AppShell`](https://github.com/svelteuidev/svelteui/blob/main/packages/svelteui-core/src/components/AppShell/AppShell.svelte) and another inteernal `<div>` in order to create a full page AppShell which expands to the height of the page.
137+
138+
[tailwindcss]: https://tailwindcss.com

0 commit comments

Comments
 (0)