Skip to content

Commit 4157578

Browse files
sfc-css-features (#174)
1 parent d75cc10 commit 4157578

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/api/sfc-css-features.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# SFC CSS Features {#sfc-css-features}
1+
# ویژگی‌های CSS در SFC {#sfc-css-features}
22

3-
## Scoped CSS {#scoped-css}
3+
## CSS دارای اسکوپ {#scoped-css}
44

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 برای تبدیل موارد زیر:
66

77
```vue
88
<style scoped>
@@ -16,7 +16,7 @@ When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements
1616
</template>
1717
```
1818

19-
Into the following:
19+
به موارد زیر:
2020

2121
```vue
2222
<style>
@@ -30,13 +30,13 @@ Into the following:
3030
</template>
3131
```
3232

33-
### Child Component Root Elements {#child-component-root-elements}
33+
### المنت ریشه کامپوننت فرزند {#child-component-root-elements}
3434

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 والد و فرزند قرار می‌گیرد. به طور عمد برای این طراحی شده است که والد بتواند عنصر ریشه فرزند را برای اهداف چیدمان، استایل بدهد.
3636

37-
### Deep Selectors {#deep-selectors}
37+
### انتخابگرهای عمیق {#deep-selectors}
3838

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()`‍ استفاده کنید:
4040

4141
```vue
4242
<style scoped>
@@ -46,21 +46,21 @@ If you want a selector in `scoped` styles to be "deep", i.e. affecting child com
4646
</style>
4747
```
4848

49-
The above will be compiled into:
49+
مورد فوق به صورت زیر کامپایل می‌شود:
5050

5151
```css
5252
.a[data-v-f3f3eg9] .b {
5353
/* ... */
5454
}
5555
```
5656

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 استایل دهید.
5959
:::
6060

61-
### Slotted Selectors {#slotted-selectors}
61+
### انتخابگرهای Slotted {#slotted-selectors}
6262

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`‍ استفاده کنید:
6464

6565
```vue
6666
<style scoped>
@@ -70,9 +70,9 @@ By default, scoped styles do not affect contents rendered by `<slot/>`, as they
7070
</style>
7171
```
7272

73-
### Global Selectors {#global-selectors}
73+
### انتخابگرهای سراسری {#global-selectors}
7474

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>`‍ دیگر استفاده کنید (در زیر مشاهده کنید):
7676

7777
```vue
7878
<style scoped>
@@ -82,29 +82,29 @@ If you want just one rule to apply globally, you can use the `:global` pseudo-cl
8282
</style>
8383
```
8484

85-
### Mixing Local and Global Styles {#mixing-local-and-global-styles}
85+
### مخلوط کردن استایل‌های محلی و سراسری {#mixing-local-and-global-styles}
8686

87-
You can also include both scoped and non-scoped styles in the same component:
87+
همچنین می‌توانید هم استایل‌های دارای scope و هم بدون scope را در یک کامپوننت داشته باشید:
8888

8989
```vue
9090
<style>
91-
/* global styles */
91+
/* استایل‌های سراسری */
9292
</style>
9393
9494
<style scoped>
95-
/* local styles */
95+
/* استایل‌های محلی */
9696
</style>
9797
```
9898

99-
### Scoped Style Tips {#scoped-style-tips}
99+
### نکاتی درباره استایل‌های دارای scope {#scoped-style-tips}
100100

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 }`، آنگاه عملاً آن افت عملکرد را حذف می‌کنید.
102102

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` در آن کامپوننت فرزند توسط این قاعده مچ خواهند شد.
104104

105105
## CSS Modules {#css-modules}
106106

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` در اختیار کامپوننت قرار می‌دهد:
108108

109109
```vue
110110
<template>
@@ -118,13 +118,13 @@ A `<style module>` tag is compiled as [CSS Modules](https://github.com/css-modul
118118
</style>
119119
```
120120

121-
The resulting classes are hashed to avoid collision, achieving the same effect of scoping the CSS to the current component only.
121+
کلاس‌های حاصل هش می‌شوند تا از تداخل جلوگیری شود، که همان اثر کپسوله کردن CSS به کامپوننت فعلی را ایجاد می‌کند.
122122

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) مراجعه کنید.
124124

125-
### Custom Inject Name {#custom-inject-name}
125+
### سفارشی سازی نام ماژول تزریق شده{#custom-inject-name}
126126

127-
You can customize the property key of the injected classes object by giving the `module` attribute a value:
127+
می‌توانید نام آبجکتی که کلاس‌های تزریق شده را ارائه می‌دهد را با دادن یک مقدار به اتریبیوت `module` سفارشی کنید:
128128

129129
```vue
130130
<template>
@@ -138,24 +138,24 @@ You can customize the property key of the injected classes object by giving the
138138
</style>
139139
```
140140

141-
### Usage with Composition API {#usage-with-composition-api}
141+
### استفاده با Composition API {#usage-with-composition-api}
142142

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` مطابق را به عنوان اولین آرگومان می‌پذیرد:
144144

145145
```js
146146
import { useCssModule } from 'vue'
147147

148-
// inside setup() scope...
149-
// default, returns classes for <style module>
148+
// setup() در محدوده
149+
// بازمی‌گرداند <style module> به طور پیش‌فرض، کلاس‌ها را برای
150150
useCssModule()
151151

152-
// named, returns classes for <style module="classes">
152+
// بازمی‌گرداند <style module="classes"> برای نامگذاری شده، کلاس‌ها را برای
153153
useCssModule('classes')
154154
```
155155

156-
## `v-bind()` in CSS {#v-bind-in-css}
156+
## `v-bind()` در CSS {#v-bind-in-css}
157157

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` پشتیبانی می‌کنند:
159159

160160
```vue
161161
<template>
@@ -179,7 +179,7 @@ export default {
179179
</style>
180180
```
181181

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) کار می‌کند و از عبارات جاوااسکریپت (باید در داخل گیومه قرار گیرند) پشتیبانی می‌کند:
183183

184184
```vue
185185
<script setup>
@@ -199,4 +199,4 @@ p {
199199
</style>
200200
```
201201

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

Comments
 (0)