@@ -16,8 +16,8 @@ include ../_util-fns
16
16
* [Using Component Styles](#using-component-styles)
17
17
* [Loading Styles into Components](#loading-styles-into-components)
18
18
* [Controlling View Encapsulation: Emulated, Native, and None](#controlling-view-encapsulation-native-emulated-and-none)
19
- * [Appendix 1: Inspecting the generated runtime component styles](#appendix-1-inspecting-the-css- generated-in-emulated-view-encapsulation )
20
- * [Appendix 2: Loading Styles with Relative URLs](#appendix-2-loading -styles-with-relative-urls)
19
+ * [Appendix 1: Inspecting the generated runtime component styles](#inspect- generated-css )
20
+ * [Appendix 2: Loading Styles with Relative URLs](#load -styles-with-relative-urls)
21
21
22
22
**[Run the live code](/resources/live-examples/component-styles/ts/plnkr.html)
23
23
shown in this chapter.**
@@ -191,33 +191,33 @@ include ../_util-fns
191
191
As described above, the CSS styles of a component are *encapsulated* into its own view and do
192
192
not affect the rest of the application.
193
193
194
- We can actually control how this encapsulation happens, and we can do that on a component per
195
- component basis. This is done by setting the *view encapsulation mode* of each component. There
196
- are three modes we can choose from:
194
+ We can actually control how this encapsulation happens, and we can do that on a * per
195
+ component* basis by setting the *view encapsulation mode* in the component metadata . There
196
+ are three modes to choose from:
197
197
198
198
* `Native` view encapsulation uses the browser's native [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)
199
199
implementation to attach a Shadow DOM to the component's host element, and then puts the component
200
200
view inside that Shadow DOM. The component's styles are included within the Shadow DOM.
201
+
201
202
* `Emulated` view encapsulation (**this is the default**) emulates the behavior of Shadow DOM by preprocessing
202
203
the CSS code in a way that scopes it to the component's view. See
203
- [Appendix 1](#appendix-1-inspecting-the-css-generated-in-emulated-view-encapsulation) for details.
204
+ [Appendix 1](#inspect-generated-css) for details.
205
+
204
206
* `None` means that no view encapsulation is applied to the component's view. All CSS styles
205
207
are applied globally, and the scoping rules discussed above do not apply. This is essentially the
206
208
same as adding the component's styles as a global stylesheet to the page.
207
209
208
- `Native` view encapsulation will only work on [browsers that have native support
209
- for Shadow DOM](http://caniuse.com/#feat=shadowdom). The support is still limited,
210
- which is why `Emulated` view encapsulation is the default mode and recommended
211
- in most cases.
212
-
213
210
We can set the view encapsulation of a component by using the `encapsulation`
214
211
attribute in the component metadata:
215
212
216
- + makeExample('component-styles/ts/app/quest-summary.native.component.ts' , 'encapsulation' )
217
-
213
+ + makeExample('component-styles/ts/app/quest-summary.component.ts' , 'encapsulation.native' )
218
214
:marked
219
-
215
+ `Native` view encapsulation only works on [browsers that have native support
216
+ for Shadow DOM](http://caniuse.com/#feat=shadowdom). The support is still limited,
217
+ which is why `Emulated` view encapsulation is the default mode and recommended
218
+ in most cases.
220
219
220
+ a( id ="#inspect-generated-css" )
221
221
.l-main-section
222
222
:marked
223
223
## Appendix 1: Inspecting The CSS Generated in Emulated View Encapsulation
@@ -266,6 +266,7 @@ code-example(format="").
266
266
secret sauce that enables the scoping rules described in this guide. At least until
267
267
Shadow DOM becomes more widely supported natively.
268
268
269
+ a( id ="load-styles-with-relative-urls" )
269
270
.l-main-section
270
271
:marked
271
272
## Appendix 2: Loading Styles with Relative URLs
0 commit comments