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: src/api/sfc-css-features.md
+36-36Lines changed: 36 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
# SFC CSS Features {#sfc-css-features}
1
+
# ویژگیهای CSS در SFC {#sfc-css-features}
2
2
3
-
## Scoped CSS {#scoped-css}
3
+
## CSS دارای اسکوپ {#scoped-css}
4
4
5
-
When a `<style>`tag has the `scoped`attribute, its CSS will apply to elements of the current component only. This is similar to the style encapsulation found in Shadow DOM. It comes with some caveats, but doesn't require any polyfills. It is achieved by using PostCSS to transform the following:
5
+
وقتی یک تگ `<style>`دارای اتریبیوت `scoped`باشد، CSS نوشته شده در آن تنها بر عناصر کامپوننت فعلی اعمال میشود. این شبیه به کپسولهسازی استایل در Shadow DOM است، اما نیازی به پلیفیل ندارد. این کار با استفاده از PostCSS برای تبدیل موارد زیر:
6
6
7
7
```vue
8
8
<style scoped>
@@ -16,7 +16,7 @@ When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements
16
16
</template>
17
17
```
18
18
19
-
Into the following:
19
+
به موارد زیر:
20
20
21
21
```vue
22
22
<style>
@@ -30,13 +30,13 @@ Into the following:
30
30
</template>
31
31
```
32
32
33
-
### Child Component Root Elements {#child-component-root-elements}
33
+
### المنت ریشه کامپوننت فرزند {#child-component-root-elements}
34
34
35
-
With`scoped`, the parent component's styles will not leak into child components. However, a child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS. This is by design so that the parent can style the child root element for layout purposes.
35
+
با`scoped`، استایلهای کامپوننت والد به کامپوننتهای فرزند نشت پیدا نمیکنند. با این حال، المنت ریشه کامپوننت فرزند تحت تأثیر هر دو CSS دارای scope والد و فرزند قرار میگیرد. به طور عمد برای این طراحی شده است که والد بتواند عنصر ریشه فرزند را برای اهداف چیدمان، استایل بدهد.
36
36
37
-
### Deep Selectors {#deep-selectors}
37
+
### انتخابگرهای عمیق {#deep-selectors}
38
38
39
-
If you want a selector in`scoped`styles to be "deep", i.e. affecting child components, you can use the `:deep()` pseudo-class:
39
+
اگر میخواهید یک سلکتور در استایلهای`scoped`اصطلاحا "deep" باشد، یعنی کامپوننتهای فرزند را تحت تأثیر قرار دهد، میتوانید از شبهکلاس `:deep()` استفاده کنید:
40
40
41
41
```vue
42
42
<style scoped>
@@ -46,21 +46,21 @@ If you want a selector in `scoped` styles to be "deep", i.e. affecting child com
46
46
</style>
47
47
```
48
48
49
-
The above will be compiled into:
49
+
مورد فوق به صورت زیر کامپایل میشود:
50
50
51
51
```css
52
52
.a[data-v-f3f3eg9] .b {
53
53
/* ... */
54
54
}
55
55
```
56
56
57
-
:::tip
58
-
DOM content created with `v-html` are not affected by scoped styles, but you can still style them using deep selectors.
57
+
:::tip نکته
58
+
محتوای DOM ایجاد شده با `v-html` تحت تأثیر استایلهای دارای scope قرار نمیگیرند، اما همچنان میتوانید آنها را با استفاده از deep selectors استایل دهید.
59
59
:::
60
60
61
-
### Slotted Selectors {#slotted-selectors}
61
+
### انتخابگرهای Slotted {#slotted-selectors}
62
62
63
-
By default, scoped styles do not affect contents rendered by `<slot/>`, as they are considered to be owned by the parent component passing them in. To explicitly target slot content, use the `:slotted` pseudo-class:
63
+
به طور پیشفرض، استایلهای دارای scope بر محتوای رندر شده توسط `<slot/>` تأثیر نمیگذارند، زیرا آنها متعلق به کامپوننت والدی در نظر گرفته میشوند که آنها را ارسال کرده است. برای هدف قرار دادن صریح محتوای اسلات، از شبهکلاس `:slotted` استفاده کنید:
64
64
65
65
```vue
66
66
<style scoped>
@@ -70,9 +70,9 @@ By default, scoped styles do not affect contents rendered by `<slot/>`, as they
70
70
</style>
71
71
```
72
72
73
-
### Global Selectors {#global-selectors}
73
+
### انتخابگرهای سراسری {#global-selectors}
74
74
75
-
If you want just one rule to apply globally, you can use the `:global` pseudo-class rather than creating another `<style>` (see below):
75
+
اگر میخواهید فقط یک قاعده به صورت سراسری اعمال شود، میتوانید از شبهکلاس `:global` به جای ایجاد یک `<style>` دیگر استفاده کنید (در زیر مشاهده کنید):
76
76
77
77
```vue
78
78
<style scoped>
@@ -82,29 +82,29 @@ If you want just one rule to apply globally, you can use the `:global` pseudo-cl
82
82
</style>
83
83
```
84
84
85
-
### Mixing Local and Global Styles {#mixing-local-and-global-styles}
85
+
### مخلوط کردن استایلهای محلی و سراسری {#mixing-local-and-global-styles}
86
86
87
-
You can also include both scoped and non-scoped styles in the same component:
87
+
همچنین میتوانید هم استایلهای دارای scope و هم بدون scope را در یک کامپوننت داشته باشید:
88
88
89
89
```vue
90
90
<style>
91
-
/* global styles */
91
+
/* استایلهای سراسری */
92
92
</style>
93
93
94
94
<style scoped>
95
-
/* local styles */
95
+
/* استایلهای محلی */
96
96
</style>
97
97
```
98
98
99
-
### Scoped Style Tips {#scoped-style-tips}
99
+
### نکاتی درباره استایلهای دارای scope {#scoped-style-tips}
100
100
101
-
-**Scoped styles do not eliminate the need for classes**. Due to the way browsers render various CSS selectors, `p { color: red }`will be many times slower when scoped (i.e. when combined with an attribute selector). If you use classes or ids instead, such as in `.example { color: red }`, then you virtually eliminate that performance hit.
101
+
-**استایلهای دارای scope نیاز به کلاسها را از بین نمیبرند**. به دلیل شیوه رندر انواع انتخابگرهای CSS در مرورگرها، `p { color: red }`زمانی که دارای scope است (یعنی وقتی با یک انتخابگر اتریبیوت ترکیب می شود) چندین برابر کندتر خواهد بود. اگر به جای آن از کلاسها یا شناسهها استفاده کنید، مانند `.example { color: red }`، آنگاه عملاً آن افت عملکرد را حذف میکنید.
102
102
103
-
-**Be careful with descendant selectors in recursive components!**For a CSS rule with the selector `.a .b`, if the element that matches `.a`contains a recursive child component, then all `.b`in that child component will be matched by the rule.
103
+
-**هنگام استفاده از انتخابگرهای فرزند در کامپوننتهای بازگشتی مراقب باشید!**(کامپوننت بازگشتی یک نوع کامپوننت است که در داخل خود، از خود استفاده میکند) برای یک قاعده CSS با انتخابگر `.a .b`، اگر عنصری که `.a`را مچ میکند حاوی یک کامپوننت فرزند بازگشتی باشد، آنگاه همه `.b`در آن کامپوننت فرزند توسط این قاعده مچ خواهند شد.
104
104
105
105
## CSS Modules {#css-modules}
106
106
107
-
A `<style module>`tag is compiled as [CSS Modules](https://github.com/css-modules/css-modules)and exposes the resulting CSS classes to the component as an object under the key of `$style`:
107
+
یک تگ `<style module>`به عنوان [CSS Modules](https://github.com/css-modules/css-modules)کامپایل میشود و کلاسهای CSS حاصل را به عنوان یک آبجکت تحت کلید `$style` در اختیار کامپوننت قرار میدهد:
108
108
109
109
```vue
110
110
<template>
@@ -118,13 +118,13 @@ A `<style module>` tag is compiled as [CSS Modules](https://github.com/css-modul
118
118
</style>
119
119
```
120
120
121
-
The resulting classes are hashed to avoid collision, achieving the same effect of scoping the CSS to the current component only.
121
+
کلاسهای حاصل هش میشوند تا از تداخل جلوگیری شود، که همان اثر کپسوله کردن CSS به کامپوننت فعلی را ایجاد میکند.
122
122
123
-
Refer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for more details such as [global exceptions](https://github.com/css-modules/css-modules#exceptions) and [composition](https://github.com/css-modules/css-modules#composition).
123
+
برای جزئیات بیشتر مانند [استثنائات سراسری](https://github.com/css-modules/css-modules#exceptions) و [ترکیب](https://github.com/css-modules/css-modules#composition)، به [CSS Modules spec](https://github.com/css-modules/css-modules) مراجعه کنید.
124
124
125
-
### Custom Inject Name {#custom-inject-name}
125
+
### سفارشی سازی نام ماژول تزریق شده{#custom-inject-name}
126
126
127
-
You can customize the property key of the injected classes object by giving the `module`attribute a value:
127
+
میتوانید نام آبجکتی که کلاسهای تزریق شده را ارائه میدهد را با دادن یک مقدار به اتریبیوت `module`سفارشی کنید:
128
128
129
129
```vue
130
130
<template>
@@ -138,24 +138,24 @@ You can customize the property key of the injected classes object by giving the
138
138
</style>
139
139
```
140
140
141
-
### Usage with Composition API {#usage-with-composition-api}
141
+
### استفاده با Composition API {#usage-with-composition-api}
142
142
143
-
The injected classes can be accessed in `setup()` and`<script setup>`via the`useCssModule`API. For `<style module>`blocks with custom injection names, `useCssModule`accepts the matching `module`attribute value as the first argument:
143
+
میتوان به کلاسهای تزریق شده در `setup()` و`<script setup>`از طریق`useCssModule`دسترسی پیدا کرد. برای بلوکهای `<style module>`با نامهای تزریقی سفارشی، `useCssModule`مقدار خاصیت `module`مطابق را به عنوان اولین آرگومان میپذیرد:
144
144
145
145
```js
146
146
import { useCssModule } from'vue'
147
147
148
-
//inside setup() scope...
149
-
//default, returns classes for <style module>
148
+
// setup() در محدوده
149
+
//بازمیگرداند <style module> به طور پیشفرض، کلاسها را برای
150
150
useCssModule()
151
151
152
-
//named, returns classes for <style module="classes">
152
+
//بازمیگرداند <style module="classes"> برای نامگذاری شده، کلاسها را برای
153
153
useCssModule('classes')
154
154
```
155
155
156
-
## `v-bind()` in CSS {#v-bind-in-css}
156
+
## `v-bind()` در CSS {#v-bind-in-css}
157
157
158
-
SFC`<style>`tags support linking CSS values to dynamic component state using the `v-bind`CSS function:
158
+
تگهای`<style>`در SFC از لینک کردن مقادیر CSS به state پویای کامپوننت با استفاده از تابع CSS `v-bind`پشتیبانی میکنند:
159
159
160
160
```vue
161
161
<template>
@@ -179,7 +179,7 @@ export default {
179
179
</style>
180
180
```
181
181
182
-
The syntax works with [`<script setup>`](./sfc-script-setup), and supports JavaScript expressions (must be wrapped in quotes):
182
+
سینتکس آن با [`<script setup>`](./sfc-script-setup) کار میکند و از عبارات جاوااسکریپت (باید در داخل گیومه قرار گیرند) پشتیبانی میکند:
183
183
184
184
```vue
185
185
<script setup>
@@ -199,4 +199,4 @@ p {
199
199
</style>
200
200
```
201
201
202
-
The actual value will be compiled into a hashed CSS custom property, so the CSS is still static. The custom property will be applied to the component's root element via inline styles and reactively updated if the source value changes.
202
+
مقدار واقعی به یک پراپرتی سفارشی CSS، بصورت هش شده تبدیل خواهد شد، بنابراین CSS همچنان استاتیک است. این پراپرتی سفارشی به عنصر ریشه کامپوننت از طریق استایلهای درونخطی اعمال میشود و اگر مقدار منبع تغییر کند، به صورت reactive بروزرسانی میشود.
0 commit comments