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
{{ message }}
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Traditionally, websites are styled using global CSS files.
5
+
古くよりウェブサイトはグローバル CSS ファイルによってスタイリングが行われてきました。
6
6
7
-
Globally-scoped CSS rules are declared in external `.css`stylesheets, and [CSS specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)and [the Cascade](https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade)determine how styles are applied.
The best way to add global styles is with a [shared layout component](/tutorial/part-three/#your-first-layout-component). This layout component is used for things that are shared throughout the site, including styles, header components, and other common items.
> **NOTE:**This pattern is implemented by default in [the default starter](https://github.com/gatsbyjs/gatsby-starter-default/blob/02324e5b04ea0a66d91c7fe7408b46d0a7eac868/src/layouts/index.js#L6).
To create a shared layout with global styles, start by creating a new Gatsby site with the [hello world starter](https://github.com/gatsbyjs/gatsby-starter-hello-world).
15
+
グローバルスタイルを使った共通レイアウトを学ぶために、 まず [hello world starter](https://github.com/gatsbyjs/gatsby-starter-hello-world) を使った新しい Gatsby サイトを作成してください。
16
16
17
17
```shell
18
18
gatsby new global-styles https://github.com/gatsbyjs/gatsby-starter-hello-world
19
19
```
20
20
21
-
Open your new site in your code editor and create a new directory at `/src/components`. Inside, create two new files:
You should see your global styles taking effect across your site:
105
+
グローバルスタイルがサイト全体に反映されているはずです:
106
106
107
107

108
108
109
-
### Importing CSS files into components
109
+
### コンポーネントの中で CSS を読み込む
110
110
111
-
It is also possible to break up your CSS styles into separate files so that team members can work independently while still using traditional CSS. You can then [import files directly](/docs/importing-assets-into-files/)into pages, templates, or components:
@@ -122,11 +122,11 @@ It is also possible to break up your CSS styles into separate files so that team
122
122
import"css/menu.css"
123
123
```
124
124
125
-
This approach can simplify integration of CSS or [Sass](/packages/gatsby-plugin-sass/) styles into your Gatsby site by allowing team members to write and consume more traditional, class-based CSS. However, there are [trade-offs](#limitations) that must be considered with regards to web performance and the lack of dead code elimination.
Since `class`is a reserved word in JavaScript, you'll have to use the `className`prop instead, which will render as the browser-supported `class`attribute in your HTML output.
129
+
`class`は JavaScript において予約語なので、代わりに `className`属性を使わなければなりません。 HTML に出力されるとブラウザサポートされた `class`属性としてレンダリングされます。
130
130
131
131
```jsx
132
132
<button className="primary">Click me</button>
@@ -138,8 +138,8 @@ Since `class` is a reserved word in JavaScript, you'll have to use the `classNam
138
138
}
139
139
```
140
140
141
-
### Limitations
141
+
### 問題解決の限界
142
142
143
-
The biggest problem with global CSS files is the risk of name conflicts and side effects like unintended inheritance.
CSS methodologies like BEM can help solve this, but a more modern solution is to write locally-scoped CSS using[CSS Modules](/docs/css-modules/)or[CSS-in-JS](/docs/css-in-js/).
145
+
この問題を解決するための助けとして BEM のような CSS 設計がありますが、より現代的な解決策は[CSS Modules](/docs/css-modules/)や[CSS-in-JS](/docs/css-in-js/) を使用したローカルスコープの CSS を記述することです。
0 commit comments