Skip to content

day8 #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

day8 #191

wants to merge 5 commits into from

Conversation

sakupi01
Copy link
Owner

@Jxck
Day8 の記事を執筆しました。お手隙でレビューいただけると幸いです!

Copy link

vercel bot commented Jul 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
blog.sakupi01.com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2025 9:27am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
git-kusa ⬜️ Skipped (Inspect) Jul 20, 2025 9:27am

Copy link

cloudflare-workers-and-pages bot commented Jul 19, 2025

Deploying studiosakupi01com with  Cloudflare Pages  Cloudflare Pages

Latest commit: 30f552b
Status: ✅  Deploy successful!
Preview URL: https://147144a9.studiosakupi01com.pages.dev
Branch Preview URL: https://feat-2025-advent-8.studiosakupi01com.pages.dev

View logs

Copy link

@Jxck Jxck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後半はコード例が出てき始めたので、前半ももうすこしあると良さそうな気はする。

あと、どこに向かってるんだかわからなくなってきたけど、面白いからまあいいや。

Comment on lines 19 to 21
前回までで、Level4 時点での Cascade について一通り解説してきました。

今日からは一旦 Cascade から離れた話題に移りたいと思います。Day8 では、CSS の基本処理について見ていきます。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前回までは、〜ました。

今日からは、一旦 Cascade から離れ、 CSS の基本処理について見ていきます。


今日からは一旦 Cascade から離れた話題に移りたいと思います。Day8 では、CSS の基本処理について見ていきます。

実際にレンダリングエンジンで CSS がどのように処理されるのか、今後の内容に直結する最低限の範囲を確認しておく温度感で進めます。CSS の中でも特に「Style Resolution」の部分にフォーカスするため、Layout や Paint などのレンダリングの過程は、今回は割愛します。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでは、今後の内容に直結する〜進めます。

実際にレンダリングエンジンで〜処理されるのかの中でも、特に「Style 〜 にフォーカスするため、〜は割愛します。


## Style Resolution

document 内の各要素に対して、ブラウザはその要素に適用される**すべての CSS プロパティ**に値を割り当てます。たった1つの `<h1>` でも 638 の CSS プロパティ(2025/07/19 時点:[Current Property Names](https://www.w3.org/Style/CSS/all-properties.en.html))が当たっており、何かしらの値を持っています。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

急な定数は意味深すぎるので、 「638 個の」をつけたほうが良い。


document 内の各要素に対して、ブラウザはその要素に適用される**すべての CSS プロパティ**に値を割り当てます。たった1つの `<h1>` でも 638 の CSS プロパティ(2025/07/19 時点:[Current Property Names](https://www.w3.org/Style/CSS/all-properties.en.html))が当たっており、何かしらの値を持っています。

メインスレッドで CSS が字句解析されパースされたあと、要素に対して単一かつ表示可能な値になるまで計算が繰り返されます。この値は、Cascade、Inheritance/依存関係、単位変換、表示環境に基づく Defaulting の計算結果です。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

字句解析 - トークナイズ
構文解析 - パース

の組み合わせのうち、なぜか斜めのペアを選んでる。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この値は、Cascade、Inheritance/依存関係、単位変換、表示環境に基づく Defaulting の計算結果です。

日本語にするのか、英語にするのかのチョイスが混ざりすぎ感。


メインスレッドで CSS が字句解析されパースされたあと、要素に対して単一かつ表示可能な値になるまで計算が繰り返されます。この値は、Cascade、Inheritance/依存関係、単位変換、表示環境に基づく Defaulting の計算結果です。

:::note{.info}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回は CSS の処理について見ていく、っていう始まりなら、これが実はメインなんじゃないか感ある。
それをすっ飛ばしていきなり Style Resolution から始めたいなら、むしろ今更これいらなそうな気も。

どのくらい読者を振り切るのか、迷いを感じる。


### Filtering

「CSS 文法上の誤りがあるものを排除する」ことが、主たる目的とする過程です。仕様上では、**[Filtering](https://www.w3.org/TR/css-cascade-4/#filtering)** と呼ばれる過程に該当します。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは流派あるかもだけど、見出しに Filtering があるとは言え、この書き出しなら「Filtering とは CSS 文法上の〜」で始まるほうが読みやすいと思う。じゃないと、「過程です」を読むまで主語が省略されてて、かつ、それが見出しだったことに気づかない。


ここでのチェックは、known property name(文法的に正しいプロパティ名)に match するかどうかだけでなく、「そもそも Style Sheet に入っているか」や「Style Rule に包含されているか」などもありますが、要は 「CSS 的に正しいかどうか静的に確認」する処理です。値が [declared value](#1-declared-values) として抽出され、適用外の値が **invalid at parse-time** となるのはこの段階です。

Filtering の結果、単一の要素に適用可能な「declared value のリスト」が得られます。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ただ、仕様を書き起こしてるだけな感じがしてしまうんだよな。
解説をするのであれば、仕様に書いてあることを噛み砕くのでなければ、仕様を読めばいいじゃんになってしまう。仕様より正確になることはないので、であれば、付加価値は「わかりやすさ」とか「時代背景」とか、仕様に無い何かが書いてあると良いと思うんだよな。

例えばこれも、具体例として間違った CSS を例に上げ、 Filtering されると内部的にはこういう扱いになりますよ、みたいなのなブレークダウンがあるとか。ブラウザの実装だとこの行ですよみたいな、リアルワールドの話があるとか。そもそもこの仕様はこういう背景でできて、、とか。
そういう何かがあったら、より良いとおもう。


Cascading の過程で、単一の宣言を採用するアルゴリズムが、 Cascading Sorting Order です。こうして宣言を単一に絞ることで、後続の [Value Processing](#value-processing) において値を単一に絞って計算していくことができます。Cascading の結果、単一に絞られた値は、**[cascaded value](#2-cascaded-value)** となります。

Cascade に関しては、このアドベントカレンダーでも多分に触れてきました。詳細は、[Day3](2025-css-advent-3)~[Day5](2025-css-advent-5) を参照されたいです。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「参照されたいです」は、デス・マスとダ・デアルが混ざってて、なんか不自然。
「参照されたい。」か「参照して下さい。」


Filtering の結果、単一の要素に対して複数の宣言が適用された場合、[Cascading](https://www.w3.org/TR/css-cascade-4/#cascading) でその競合を解決しなければなりません。

UA Stylesheet、User Stylesheet、Author Stylesheet、その中でもインラインスタイルや `@import` でのスタイル読み込みなど、さまざまなソースからすべてのスタイルを集約し、最終的に唯一の宣言を採用する必要があります。Author StyleSheet で何も指定していなくとも、ほとんどのブラウザで UA StyleSheet が適用されていることを鑑みると、この過程は必須と言っても良いでしょう。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下と同じように「Author/User/UA Stylesheet」の方が見やすいと思う。

:::note{.memo}
💡 FUN FACT

UA Stylesheet によって設定される値と initial value は異なります。例えば、`<div>` の `display` は UA Stylesheet によって `block` に設定されますが、`display` プロパティ自体の initial value は `inline` です。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UA Stylesheet によって設定される値と initial value は異なります。

この対は「仕様に定義される initial value」みたいに明示されてた方がわかりやすそう。

@vercel vercel bot temporarily deployed to Preview – git-kusa July 20, 2025 09:26 Inactive
@sakupi01
Copy link
Owner Author

@Jxck
レビューありがとうございます!諸々修正&追加しました。

あと、どこに向かってるんだかわからなくなってきた

ちょっとこれは、day9 でまとめを入れることにしました orz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants