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: packages/document/main-doc/docs/en/guides/basic-features/css.mdx
+37-27Lines changed: 37 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,33 +4,33 @@ sidebar_position: 2
4
4
5
5
# CSS Solutions
6
6
7
-
Modern.js has built-in multiple CSS solutions, including Less / Sass / Stylus preprocessor, PostCSS, CSS Modules, CSS-in-JS and Tailwind CSS.
7
+
Modern.js has built-in a variety of commonly used CSS solutions, including Less / Sass / Stylus preprocessors, PostCSS, CSS Modules, CSS-in-JS, and Tailwind CSS.
8
8
9
9
## Using Less, Sass and Stylus
10
10
11
-
Modern.js has built-in community popular CSS preprocessors such as Less, Sass.
11
+
Modern.js has built-in popular community CSS preprocessors, including Less and Sass.
12
12
13
-
By default, you don't need to configure anything for Less and Sass. If you need to customize loader config, you can configure [tools.less](/configure/app/tools/less), [tools.sass](/configure/app/tools/sass) to set it up.
13
+
By default, you don't need to configure Less and Sass. If you have custom loader configuration requirements, you can set them up by configuring [tools.less](/configure/app/tools/less) and [tools.sass](/configure/app/tools/sass).
14
14
15
-
You can also use Stylus in Modern.js, just install the Stylus plugin provided by Modern.js Builder, please refer to [Stylus Plugin](https://modernjs.dev/builder/en/plugins/plugin-stylus.html) for usage.
15
+
You can also use Stylus in Modern.js by installing the Stylus plugin provided by Modern.js Builder. For usage, please refer to [Stylus Plugin](https://modernjs.dev/builder/plugins/plugin-stylus.html).
16
16
17
17
## Using PostCSS
18
18
19
-
Modern.js has built-in [PostCSS](https://postcss.org/) to transform the CSS code.
19
+
Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
20
20
21
21
Please refer to [Modern.js Builder - Using PostCSS](https://modernjs.dev/builder/en/guide/basic/css-usage.html#using-postcss) for detailed usage.
22
22
23
23
## Using CSS Modules
24
24
25
-
Please read the [Using CSS Modules](https://modernjs.dev/builder/en/guide/basic/css-modules.html)chapter for a complete usage of CSS Modules.
25
+
Please read the [Using CSS Modules](https://modernjs.dev/builder/en/guide/basic/css-modules.html)section to learn about the complete usage of CSS Modules.
26
26
27
27
## Using CSS-in-JS
28
28
29
-
CSS-in-JS is a technology that can write CSS styles in JS files.
29
+
CSS-in-JS is a technique that allows you to write CSS styles in JS files.
30
30
31
-
Modern.js integrates the CSS-in-JS library [styled-components](https://styled-components.com/) commonly used in the community, which uses the new feature of JavaScript [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write CSS styles for components. You can use the [styled-components](https://styled-components.com/)API directly from `@modern-js/runtime/styled`.
31
+
Modern.js integrates the popular CSS-in-JS implementation library [styled-components](https://styled-components.com/), which uses the new JavaScript feature [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write component CSS styles. You can directly import the API of [styled-components](https://styled-components.com/) from `@modern-js/runtime/styled` for use.
32
32
33
-
When you need to write a `div` component with an internal font in red, you can do the following implementation:
33
+
When you need to write a `div` component with an internal font color of red, you can implement it as follows:
34
34
35
35
```js
36
36
importstyledfrom'@modern-js/runtime/styled';
@@ -40,7 +40,7 @@ const RedDiv = styled.div`
40
40
`;
41
41
```
42
42
43
-
When you need to dynamically set the component style according to the `props` of the component, for example, when the attribute `primary` of `props` is `true`, the color of the button is white, and otherwise it is red. The implementation code is as follows:
43
+
If you need to dynamically set component styles based on the component's `props`, for example, the `primary`property of `props` is `true`, the button color is white, otherwise it is red, you can implement the code as follows:
44
44
45
45
```js
46
46
importstyledfrom'@modern-js/runtime/styled';
@@ -51,34 +51,44 @@ const Button = styled.button`
51
51
`;
52
52
```
53
53
54
-
For more usage of styled-components, please refer to [[styled-components official website](https://styled-components.com/)].
54
+
For more usage of styled-components, please refer to [styled-components official website](https://styled-components.com/).
55
55
56
-
Modern.js uses the Babel plugin [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) internally, and the plugin can be configured through [tools.styledComponents](/configure/app/tools/styled-components).
56
+
Modern.js integrates Babel's [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components)plugin internally, and you can configure the plugin through [tools.styledComponents](/configure/app/tools/styled-components).
57
57
58
58
:::tip
59
-
If you need to use [styled-jsx](https://www.npmjs.com/package/styled-jsx), [Emotion](https://emotion.sh/) and other CSS-in-JS libraries, you need to install the dependency of the corresponding library first. For specific usage, please refer to the official website of the corresponding library.
59
+
If you need to use other CSS-in-JS libraries such as [styled-jsx](https://www.npmjs.com/package/styled-jsx) and [Emotion](https://emotion.sh/), you need to install the corresponding dependencies first. For specific usage, please refer to the library's official website.
60
60
:::
61
61
62
62
## Using Tailwind CSS
63
63
64
-
[Tailwind CSS](https://tailwindcss.com/) is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles. To use [Tailwind CSS](https://tailwindcss.com/) in the Modern.js, just execute`pnpm run new` in the project root directory and turn it on.
64
+
[Tailwind CSS](https://tailwindcss.com/) is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles. To use [Tailwind CSS](https://tailwindcss.com/) in Modern.js, simply run`pnpm run new` in the project root directory and enable it.
65
65
66
-
Choose as follows:
66
+
Follow the steps below to make a selection:
67
67
68
68
```bash
69
69
? Action: Enable features
70
70
? Enable features: Enable Tailwind CSS
71
71
```
72
72
73
-
When using, add the following code to the root component of the entry (such as `src/App.jsx`):
73
+
Register the Tailwind plugin in `modern.config.ts`:
To use, add the following code to the root component (such as `src/App.jsx`) of the entry:
74
84
75
85
```js
76
86
import'tailwindcss/base.css';
77
87
import'tailwindcss/components.css';
78
88
import'tailwindcss/utilities.css';
79
89
```
80
90
81
-
You can then use the Utility Class provided by Tailwind CSS in each component:
91
+
Then you can use the Utility Class provided by Tailwind CSS in each component:
82
92
83
93
```tsx
84
94
const App = () => (
@@ -88,14 +98,14 @@ const App = () => (
88
98
);
89
99
```
90
100
91
-
:::info Additional
92
-
According to different needs, you can optionally import the CSS files provided by Tailwind CSS. Since the use of `@taiwind` is equivalent to directly importing CSS files, you can refer to the content in the annotate in the [`@tailwind` usage](https://tailwindcss.com/docs/functions-and-directives#tailwind)document for the purpose of the CSS files provided by Tailwind CSS.
101
+
:::info Additional Information
102
+
Depending on your needs, you can selectively import the CSS files provided by Tailwind CSS. Since using `@tailwind` is equivalent to directly importing CSS files, you can refer to the comments in the [`@tailwind` usage](https://tailwindcss.com/docs/functions-and-directives#tailwind)documentation for the purpose of the CSS files provided by Tailwind CSS.
93
103
94
104
:::
95
105
96
-
### Tailwind CSS version
106
+
### Tailwind CSS Version
97
107
98
-
Modern.js supports both Tailwind CSS v2 and v3. The framework will recognize the version of `tailwindcss` in the project `package.json` and apply the corresponding configuration. By default, we install Tailwind CSS v3 for you.
108
+
Modern.js supports both Tailwind CSS v2 and v3 versions, and the framework will recognize the version of the `tailwindcss`dependency in the project `package.json`file and enable the corresponding configuration. By default, we will install Tailwind CSS v3 version for you.
99
109
100
110
If your project is still using Tailwind CSS v2, we recommend that you upgrade to v3 to support JIT and other capabilities. For the differences between Tailwind CSS v2 and v3 versions, please refer to the following articles:
101
111
@@ -104,16 +114,16 @@ If your project is still using Tailwind CSS v2, we recommend that you upgrade to
104
114
105
115
### Browser Compatibility
106
116
107
-
Both Tailwind CSS v2 and v3 do not support IE 11 browsers. For background, please refer to:
117
+
Tailwind CSS v2 and v3 do not support the IE 11 browser, please refer to:
If you use Tailwind CSS on IE 11 browser, some styles may not be available, please pay attention.
122
+
If you use Tailwind CSS on IE 11 browser, some styles may not be available, please use it with caution.
113
123
114
-
### Theme config
124
+
### Theme Configuration
115
125
116
-
When you need to customize the [theme](https://tailwindcss.com/docs/theme) configuration of Tailwind CSS, you can modify it in the configuration [`source.designSystem`](/configure/app/source/design-system), for example, add a color theme `primary`:
126
+
When you need to customize the [theme](https://tailwindcss.com/docs/theme) configuration of Tailwind CSS, you can modify it in the [`source.designSystem`](/configure/app/source/design-system) configuration. For example, adding a `primary` color theme:
117
127
118
128
```ts title="modern.config.ts"
119
129
exportdefaultdefineConfig({
@@ -129,7 +139,7 @@ export default defineConfig({
129
139
});
130
140
```
131
141
132
-
When you need special configuration for Tailwind CSS other than [theme](https://tailwindcss.com/docs/theme), you can configure it in [`tools.tailwindcss`](/configure/app/tools/tailwindcss), for example setting `variants`:
142
+
When you need to make other special configurations to Tailwind CSS besides [theme](https://tailwindcss.com/docs/theme), you can configure them in [`tools.tailwindcss`](/configure/app/tools/tailwindcss), such as setting `variants`:
133
143
134
144
```ts title="modern.config.ts"
135
145
exportdefaultdefineConfig({
@@ -145,4 +155,4 @@ export default defineConfig({
145
155
});
146
156
```
147
157
148
-
> When configuring Tailwind CSS for a project, the combination of the two configurations [source.designSystem](/configure/app/source/design-system) and [tools.tailwindcss](/configure/app/tools/tailwindcss) is equivalent to a separate configuration `tailwindcss.config.js` file. Where [source.designSystem](/configure/app/source/design-system) is equivalent to the [theme](https://v2.tailwindcss.com/docs/configuration#theme) configuration of Tailwind CSS.
158
+
> When you configure Tailwind CSS for your project, the combination of [source.designSystem](/configure/app/source/design-system) and [tools.tailwindcss](/configure/app/tools/tailwindcss)configurations is equivalent to configuring a `tailwindcss.config.js` file separately. [source.designSystem](/configure/app/source/design-system) is equivalent to the Tailwind CSS [theme](https://v2.tailwindcss.com/docs/configuration#theme) configuration.
0 commit comments