`元素为目标,从宿主元素到当前元素再到 DOM 中的所有子元素:
The `/deep/` combinator also has the aliases `>>>`, and `::ng-deep`.
`/deep/` 组合器还有两个别名:`>>>`和`::ng-deep`。
Use `/deep/`, `>>>` and `::ng-deep` only with *emulated* view encapsulation.
Emulated is the default and most commonly used view encapsulation. For more information, see the
[Controlling view encapsulation](guide/component-styles#view-encapsulation) section.
`/deep/`和`>>>`选择器只能被用在**仿真 (emulated) **模式下。
这种方式是默认值,也是用得最多的方式。
更多信息,见[控制视图封装模式](guide/component-styles#view-encapsulation)一节。
The shadow-piercing descendant combinator is deprecated and [support is being removed from major browsers](https://www.chromestatus.com/features/6750456638341120) and tools.
As such we plan to drop support in Angular (for all 3 of `/deep/`, `>>>` and `::ng-deep`).
Until then `::ng-deep` should be preferred for a broader compatibility with the tools.
CSS标准中用于 "刺穿Shadow DOM" 的组合器已经被废弃,并将[这个特性从主流浏览器和工具中移除](https://www.chromestatus.com/features/6750456638341120)。
因此,我们也将在 Angular 中移除对它们的支持(包括`/deep/`、`>>>` 和 `::ng-deep`)。
目前,建议先统一使用`::ng-deep`,以便兼容将来的工具。
{@a loading-styles}
## Loading component styles
## 把样式加载进组件中
There are several ways to add styles to a component:
有几种方式把样式加入组件:
* By setting `styles` or `styleUrls` metadata.
设置`styles`或`styleUrls`元数据
* Inline in the template HTML.
内联在模板的 HTML 中
* With CSS imports.
通过 CSS 文件导入
The scoping rules outlined earlier apply to each of these loading patterns.
上述作用域规则对所有这些加载模式都适用。
### Styles in metadata
### 元数据中的样式
You can add a `styles` array property to the `@Component` decorator.
Each string in the array (usually just one string) defines the CSS.
我们可以给`@Component`装饰器添加一个`styles`数组型属性。
这个数组中的每一个字符串(通常也只有一个)定义一份 CSS。
### Style URLs in metadata
### 元数据中指定样式表的URL
You can load styles from external CSS files by adding a `styleUrls` attribute
into a component's `@Component` decorator:
通过在组件的`@Component`装饰器中添加`styleUrls`属性,我们可以从外部CSS文件中加载样式:
The URL is relative to the *application root*, which is usually the
location of the `index.html` web page that hosts the application.
The style file URL is *not* relative to the component file.
That's why the example URL begins `src/app/`.
To specify a URL relative to the component file, see [Appendix 2](guide/component-styles#relative-urls).
URL是***相对于应用程序根目录的***,它通常是应用的宿主页面`index.html`所在的地方。
这个样式文件的 URL *不是*相对于组件文件的。这就是为什么范例中的 URL 用`src/app/`开头。
参见[附录 2](guide/component-styles#relative-urls) 来了解如何指定相对于组件文件的 URL。
If you use module bundlers like Webpack, you can also use the `styles` attribute
to load styles from external files at build time. You could write:
像 Webpack 这类模块打包器的用户可能会使用`styles`属性来在构建时从外部文件中加载样式。它们可能这样写:
`styles: [require('my.component.css')]`
Set the `styles` property, notthe `styleUrls` property. The module
bundler loads the CSS strings, not Angular.
Angular sees the CSS strings onlyafter the bundler loads them.
To Angular, it 's as if you wrote the `styles` array by hand.
For information on
loading CSS in this manner, refer to the module bundler's documentation.
注意,这时候我们是在设置`styles`属性,**而不是**`styleUrls`属性!
是模块打包器在加载 CSS 字符串,而不是 Angular。
Angular 看到的只是打包器加载它们之后的 CSS 字符串。
对 Angular 来说,这跟我们手写了`styles`数组没有任何区别。
要了解这种 CSS 加载方式的更多信息,请参阅相应模块打包器的文档。
### Template inline styles
### 模板内联样式
You can embed styles directly into the HTML template by putting them
inside `