You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,20 @@ Import the `style.scss` file in your main SCSS file:
87
87
@import'minimal-css-utility/scss/style.scss';
88
88
```
89
89
90
+
### CSS Scoping
91
+
92
+
You can scope all the generated CSS under a specific parent selector (e.g., `.my-app`) by configuring the `$css-scope` variable. Since this project uses Sass modules, you need to configure the variables module before loading the styles.
Minimal CSS Utility provides an option to scope all generated styles under a specific parent selector. This is particularly useful when you are using the library in an embedded context (e.g., a widget or a micro-frontend) and want to avoid style conflicts with the host application.
4
+
5
+
## Configuration
6
+
7
+
To enable scoping, you need to configure the `$css-scope` variable in the `abstracts/variables` module.
8
+
9
+
### Using Sass Modules
10
+
11
+
Since this library uses Sass modules, you should use the `@use ... with` syntax to configure the variable.
12
+
13
+
```scss
14
+
// main.scss
15
+
16
+
// 1. Configure the variables module with your desired scope selector
The above configuration will wrap all generated CSS rules (including reset, grid, and utilities) inside the `.my-custom-scope` selector.
28
+
29
+
```css
30
+
.my-custom-scope {
31
+
/* Reset styles */
32
+
margin: 0;
33
+
padding: 0;
34
+
/* ... */
35
+
}
36
+
37
+
.my-custom-scope.row {
38
+
display: flex;
39
+
/* ... */
40
+
}
41
+
42
+
.my-custom-scope.text-center {
43
+
text-align: center!important;
44
+
}
45
+
```
46
+
47
+
## HTML Usage
48
+
49
+
In your HTML, simply wrap your application content with the configured class.
50
+
51
+
```html
52
+
<divclass="my-custom-scope">
53
+
<divclass="container">
54
+
<h1class="text-center">Scoped Content</h1>
55
+
<!-- ... -->
56
+
</div>
57
+
</div>
58
+
```
59
+
60
+
## Framework Examples
61
+
62
+
### React
63
+
64
+
In a React application, you can import the configured SCSS file in your root component (e.g., `App.jsx`) and wrap your application with the scope class.
0 commit comments