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-style.md
+33-33Lines changed: 33 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
sidebarDepth: 1
3
3
---
4
4
5
-
# SFC Style Features
5
+
# SFC スタイルの機能
6
6
7
7
## `<style scoped>`
8
8
9
-
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:
9
+
`<style>`タグが `scoped`属性を持つとき、その CSS は現在のコンポーネントの要素にだけ適用されます。これは Shadow DOM に見られるスタイルのカプセル化に似ています。いくつかの注意点がありますが、ポリフィルは必要ありません。これは PostCSS を使った次のような変換で実現しています:
10
10
11
11
```vue
12
12
<style scoped>
@@ -20,7 +20,7 @@ When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements
20
20
</template>
21
21
```
22
22
23
-
Into the following:
23
+
次のようになります:
24
24
25
25
```vue
26
26
<style>
@@ -34,13 +34,13 @@ Into the following:
34
34
</template>
35
35
```
36
36
37
-
### Child Component Root Elements
37
+
### 子コンポーネントのルート要素
38
38
39
-
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.
@@ -50,7 +50,7 @@ If you want a selector in `scoped` styles to be "deep", i.e. affecting child com
50
50
</style>
51
51
```
52
52
53
-
The above will be compiled into:
53
+
上記は次のようにコンパイルされます:
54
54
55
55
```css
56
56
.a[data-v-f3f3eg9] .b {
@@ -59,12 +59,12 @@ The above will be compiled into:
59
59
```
60
60
61
61
:::tip
62
-
DOM content created with `v-html`are not affected by scoped styles, but you can still style them using deep selectors.
62
+
`v-html`で作られた DOM コンテンツは、スコープ付きスタイルの影響を受けませんが、ディープセレクタを使ってスタイルすることができます。
63
63
:::
64
64
65
-
### Slotted Selectors
65
+
### スロットセレクタ
66
66
67
-
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:
@@ -86,29 +86,29 @@ If you want just one rule to apply globally, you can use the `:global` pseudo-cl
86
86
</style>
87
87
```
88
88
89
-
### Mixing Local and Global Styles
89
+
### ローカルとグローバルのスタイル併用
90
90
91
-
You can also include both scoped and non-scoped styles in the same component:
91
+
スコープ付きとスコープなしのスタイルの両方を同じコンポーネントに含めることもできます:
92
92
93
93
```vue
94
94
<style>
95
-
/* global styles */
95
+
/* グローバルスタイル */
96
96
</style>
97
97
98
98
<style scoped>
99
-
/* local styles */
99
+
/* ローカルスタイル */
100
100
</style>
101
101
```
102
102
103
-
### Scoped Style Tips
103
+
### スコープ付きスタイルのヒント
104
104
105
-
-**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.
105
+
-**スコープ付きスタイルでもクラスが不要になるわけではないです**。ブラウザがさまざまな CSS セレクタをレンダリングする方法のため、`p { color: red }`はスコープ付きの場合(例えば属性セレクタと合わせた場合)に何杯も遅くなります。`.example { color: red }` のようにクラスや ID を代わりに使えば、このパフォーマンスへの影響をほぼ解消することができます。
106
106
107
-
-**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.
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`:
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).
@@ -144,21 +144,21 @@ You can customize the property key of the injected classes object by giving the
144
144
</style>
145
145
```
146
146
147
-
### Usage with Composition API
147
+
### Composition API での使用
148
148
149
-
The injected classes can be accessed in `setup()` and `<script setup>` via the [`useCssModule`](/api/global-api.html#usecssmodule) API. For `<style module>`blocks with custom injection names, `useCssModule`accepts the matching `module`attribute value as the first argument:
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.
0 commit comments