From e2f38a503d2aab5934a2854d0a7f4df22300aa93 Mon Sep 17 00:00:00 2001 From: Kesus Kim Date: Mon, 13 Mar 2017 10:50:20 +0900 Subject: [PATCH 1/5] Trans(component-styles.jade): All --- .../ts/latest/guide/component-styles.jade | 399 +++++++++++++----- 1 file changed, 294 insertions(+), 105 deletions(-) diff --git a/public/docs/ts/latest/guide/component-styles.jade b/public/docs/ts/latest/guide/component-styles.jade index 0527c3d4..bf63fab7 100644 --- a/public/docs/ts/latest/guide/component-styles.jade +++ b/public/docs/ts/latest/guide/component-styles.jade @@ -2,124 +2,201 @@ block includes include ../_util-fns :marked + Angular 어플리케이션은 스타일시트로 일반적인 CSS를 이용합니다. 즉 우리가 + CSS 스타일시트에 대해 알고 있는 모든 것, 가령 선택자나 규칙, 미디어쿼리 등을 + Angular 어플리케이션에 직접 사용할 수 있어요. + Angular applications are styled with regular CSS. That means we can apply everything we know about CSS stylesheets, selectors, rules, and media queries to our Angular applications directly. - + + 그 외에도, Angular는 *컴포넌트 스타일*을 이용하여 일반적인 CSS 보다 더욱 체계적으로 + 모듈화를 하여 번들링 할 수 있는 능력이 있습니다. + On top of this, Angular has the ability to bundle *component styles* with our components enabling a more modular design than regular stylesheets. - + + 이번 챕터에서는 이러한 *컴포넌트 스타일*을 어떻게 사용하고 적용할 수 있는지 배워볼거에요. + In this chapter we learn how to load and apply these *component styles*. - - ## Table Of Contents - * [Using Component Styles](#using-component-styles) - * [Special selectors](#special-selectors) - * [Loading Styles into Components](#loading-styles) - * [Controlling View Encapsulation: Emulated, Native, and None](#view-encapsulation) - * [Appendix 1: Inspecting the generated runtime component styles](#inspect-generated-css) - * [Appendix 2: Loading Styles with Relative URLs](#relative-urls) + ## 목차 - Run the of the code shown in this chapter. + * [컴포넌트 스타일 사용하기](#using-component-styles) + * [특별한 선택자](#special-selectors) + * [컴포넌트에 스타일 불러오기](#loading-styles) + * [뷰 캡슐화 제어하기: Emulated, Native, and None](#view-encapsulation) + * [부록 1: 생성된 런타임 컴포넌트 스타일 탐색하기](#inspect-generated-css) + * [부록 2: 상대 경로 URL을 이용하여 스타일 불러오기](#relative-urls) + + 이 페이지의 예제는 에서 확인 가능합니다. .l-main-section :marked - ## Using Component Styles - + ## 컴포넌트 스타일 사용하기 + + 우리가 작성하는 모든 Angular 컴포넌트에 대해, 우리는 HTML 템플릿뿐만 아니라, + 템플릿과 같이 동작하는 CSS 스타일(선택자, 규칙, 미디어 쿼리 등)도 정의합니다. + For every Angular component we write, we may define not only an HTML template, - but also the CSS styles that go with that template, + but also the CSS styles that go with that template, specifying any selectors, rules, and media queries that we need. + 이를 하기 위한 방법 중 하나는 컴포넌트 내의 메타데이터에 `styles` 속성 값을 설정하는 것 입니다. + `styles` 속성 값은 CSS 코드가 포함된 문자열의 배열을 취합니다. + 보통 아래의 예제와 같이 하나의 문자열만을 주지요. + One way to do this is to set the `styles` property in the component metadata. The `styles` property takes #{_an} #{_array} of strings that contain CSS code. Usually we give it one string as in this example: - + +makeExample('component-styles/ts/src/app/hero-app.component.ts')(format='.') :marked + 컴포넌트 스타일은 전통적이며, 전역적으로 스타일을 작성하는 방법과 몇 가지가 다릅니다. + Component styles differ from traditional, global styles in a couple of ways. - + + 먼저 컴포넌트 스타일 안에 넣는 선택자들은 *오직 해당하는 컴포넌트의 템플릿 안에서만 적용됩니다.* 위의 예제에서의 + `h1` 선택자는 `HeroAppComponent` 템플릿 내의 `

` 태그에만 적용되며, 어플리케이션 내의 그 밖의 `

` 태그에는 영향을 미치지 않습니다. + Firstly, the selectors we put into a component's styles *only apply within the template of that component*. The `h1` selector in the example above only applies to the `

` tag in the template of `HeroAppComponent`. Any `

` elements elsewhere in the application are unaffected. - + + 이것은 전통적인 CSS가 동작하는 방식에 비하여 모듈화에 있어서 다음과 같은 개선점을 가지고 있습니다. + This is a big improvement in modularity compared to how CSS traditionally works: - - 1. We can use the CSS class names and selectors that make the most sense in the context of each component. - - 1. Class names and selectors are local to the component and won't collide with + + 1. 각각의 컴포넌트의 상황에 최적화 된 선택자와 클래스 이름을 사용할 수 있다. + + 1. We can use the CSS class names and selectors that make the most sense in the context of each component. + + 1. 클래스 이름과 선택자들은 해당 컴포넌트에 지역적이며, 어플리케이션 내의 다른 곳에서 사용되고 있는 + 다른 클래스들이나 선택자들과 겹치지 않는다. + + 1. Class names and selectors are local to the component and won't collide with classes and selectors used elsewhere in the application. - + + 1. 컴포넌트의 스타일은 어플리케이션의 다른 곳에서 스타일을 변경함으로써 *변경할 수 없다*. + 1. Our component's styles *cannot* be changed by changes to styles elsewhere in the application. - + + 1. 각각의 컴포넌트의 CSS 코드는 TypeScript 와 HTML 코드 내에 동시에 적용할 수 있으며, + 이는 프로젝트 구조를 정리하는데에 도움이 된다. + 1. We can co-locate the CSS code of each component with the TypeScript and HTML code of the component, which leads to a neat and tidy project structure. - + + 1. 미래의 어느 시점에 해당 코드가 어디에 또 사용되었는지 찾아보는 고통을 겪지 않고도 + 컴포넌트의 CSS 코드를 변경하거나 제거할 수 있다. 그저 컴포넌트 내에 있는 코드만 보면 된다. + 1. We can change or remove component CSS code in the future without trawling through the whole application to see where else it may have been used. We just look at the component we're in. a(id="special-selectors") .l-main-section :marked - ## Special selectors - - Component styles have a few special *selectors* from the world of + ## 특별한 선택자들 + + 컴포넌트 스타일에는 [shadow DOM 스타일의 스코핑](https://www.w3.org/TR/css-scoping-1) 으로부터 파생된 몇몇 특별한 *선택자들*이 있습니다. + + Component styles have a few special *selectors* from the world of [shadow DOM style scoping](https://www.w3.org/TR/css-scoping-1): - + ### :host + `:host` 가상 클래스 선택자를 해당 컴포넌트의 *상위 컴포넌트*를 선택하기 위해 사용하세요. + (컴포넌트 템플릿 *내에 존재하는* 엘리먼트를 선택하는 경우와는 반대로 말이에요.) + Use the `:host` pseudo-class selector to target styles in the element that *hosts* the component (as opposed to targeting elements *inside* the component's template): - + +makeExample('component-styles/ts/src/app/hero-details.component.css', 'host')(format='.') :marked + 이 방법은 상위 엘리먼트를 선택할 수 있는 *유일한* 방법입니다. 다른 선택자들로는 + 상위 엘리먼트에 절대 선택할 수 없어요, 왜냐면 그 엘리먼트는 컴포넌트의 템플릿에 속하지 않았으니까요. + 그 엘리먼트는 해당 엘리먼트의 상위 컴포넌트의 템플릿에 속해있지요. + This is the *only* way we can target the host element. We cannot reach it from inside the component with other selectors, because it is not part of the component's own template. It is in a parent component's template. - - Use the *function form* to apply host styles conditionally by + + `:host` 다음에 오는 소괄호에 다른 선택자를 포함하여, *함수의 형태*를 사용하여 + 조건에 따라 상위 엘리먼트의 스타일을 적용하세요. + + Use the *function form* to apply host styles conditionally by including another selector inside parentheses after `:host`. - + + 다음의 예제는 `active` 클래스를 가지고 있는 경우에 상위 엘리먼트를 선택할 것입니다. + In the next example we target the host element again, but only when it also has the `active` CSS class. - + +makeExample('component-styles/ts/src/app/hero-details.component.css', 'hostfunction')(format=".") - + :marked ### :host-context - + + 때때로 컴포넌트의 뷰의 *외부*에서 어떤 조건에 따라 스타일을 적용하는 것이 좋을 때가 있습니다. + 예를 들어, 문서의 `` 엘리먼트에 적용되는 CSS 테마 클래스가 있을 수 있죠. 이 테마를 기반으로 + 우리의 컴포넌트도 맞춰서 변경하고 싶다고 해봐요. + Sometimes it is useful to apply styles based on some condition *outside* a component's view. For example, there may be a CSS theme class applied to the document `` element, and we want to change how our component looks based on that. - + + `:host-context()` 가상 선택자를 사용하세요. 이 선택자는 `:host()` 함수처럼 동작합니다. + 이 선택자는 해당 컴포넌트의 *모든 부모* 엘리먼트들의 CSS 클래스를 찾아냅니다. + 문서의 최상위 엘리먼트인 `` 엘리먼트까지요. 이것은 다른 선택자들과 조합하였을 때 굉장히 유용합니다. + Use the `:host-context()` pseudo-class selector. It works just like the function form of `:host()`. It looks for a CSS class in *any ancestor* of the component host element, all the way up to the document root. It's useful when combined with another selector. - + + 다음의 예제는, 어떠한 부모 엘리먼트가 `theme-light` 이라는 CSS 클래스를 가지고 있는 경우에 대해, + 컴포넌트 내의 `

` 엘리먼트에 `background-color` 스타일을 적용합니다. + In the following example, we apply a `background-color` style to all `

` elements *inside* the component, only if some ancestor element has the CSS class `theme-light`. - + + +makeExample('component-styles/ts/src/app/hero-details.component.css', 'hostcontext')(format='.') - + :marked ### /deep/ - - Component styles normally apply only to the HTML in the component's own template. - + + 컴포넌트 스타일은 일반적으로 컴포넌트의 템플릿 내에 존재하는 HTML에 대해서만 적용됩니다. + + Component styles normally apply only to the HTML in the component's own template. + + `/deep/` 선택자를 이용하여 모든 자식 컴포넌트 뷰에 대해 스타일을 전부 적용시키도록 강제할 수 있습니다. + `/deep/` 선택자는 컴포넌트가 어떠한 깊이에 있든, 얼마나 많이 겹쳐 있든 상관없이 적용되며, 컴포넌트의 + *View Children과 Content Children 모두*에 적용됩니다. + We can use the `/deep/` selector to force a style down through the child component tree into all the child component views. The `/deep/` selector works to any depth of nested components, and it applies *both to the view - children and the content children* of the component. - - In this example, we target all `

` elements, from the host element down - through this component to all of its child elements in the DOM: + children and the content children* of the component. + + 다음의 예제는, 상위 엘리먼트부터 해당 컴포넌트에 이르기까지 DOM 내의 모든 자식 엘리먼트에 대해 + `

` 엘리먼트를 선택합니다. + + In this example, we target all `

` elements, from the host element down + through this component to all of its child elements in the DOM: + +makeExample('component-styles/ts/src/app/hero-details.component.css', 'deep')(format=".") :marked + `/deep/` 선택자는 별칭으로 `>>>` 를 가지고 있습니다. 두 가지를 마음껏 바꾸어 사용할 수 있습니다. + The `/deep/` selector also has the alias `>>>`. We can use either of the two interchangeably. .alert.is-important :marked + `/deep/`과 `>>>` 선택자는 **emulated** 뷰 캡슐화에 대해서만 사용되어야 합니다. + 이것은 기본 값이며, 대개 그렇게 사용합니다. 자세한 내용에 대해서는 [뷰 캡슐화 제어](#view-encapsulation) 부분을 참조하세요. + The `/deep/` and `>>>` selectors should only be used with **emulated** view encapsulation. This is the default and it is what we use most of the time. See the [Controlling View Encapsulation](#view-encapsulation) @@ -128,115 +205,189 @@ a(id="special-selectors") a(id='loading-styles') .l-main-section :marked - ## Loading Styles into Components - - We have several ways to add styles to a component: + ## 컴포넌트로 스타일 불러오기 + + 컴포넌트에 스타일을 더하는 여러 가지 방법이 있습니다. + + We have several ways to add styles to a component: + + * 템플릿 HTML에 인라인 `