Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AngularアプリケーションにおけるCSS設計手法
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
kou
June 16, 2018
Programming
6.1k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AngularアプリケーションにおけるCSS設計手法
AngularアプリケーションでどのようにCSSが書けるのかということにフォーカスして、CSSの書き方を紹介します。
kou
June 16, 2018
More Decks by kou
See All by kou
Angular Webアプリケーションの最新設計手法.pdf
koumatsumot0
7
12k
NgRx v7
koumatsumot0
1
540
NgRxについて考えたこと
koumatsumot0
0
270
きれいなCSSを書くためのTools
koumatsumot0
0
460
Other Decks in Programming
See All in Programming
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
16k
AWSに止められる覚悟してますか?
morizo_1984
2
530
R8 の設定見直しでアプリサイズ削減
andpad
0
210
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
210
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
380
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
wkhtmltopdfの次どうするか問題2026
willnet
2
1.9k
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
230
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
370
残高管理から台帳サービスへの進化
artoy
1
200
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
590
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Mind Mapping
helmedeiros
1
400
Google's AI Overviews - The New Search
badams
0
1.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The Language of Interfaces
destraynor
162
27k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
30 Presentation Tips
portentint
PRO
1
430
A designer walks into a library…
pauljervisheath
211
25k
The untapped power of vector embeddings
frankvandijk
2
1.9k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
750
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Transcript
AngularアプリケーションにおけるCSS設計手法 ng-japan 2018
@kou bitbank, inc Cryptocurrency Exchange
CSS設計とは ?
CSS設計とは ? - BEM - SMACSS - OOCSS
なぜCSS設計が必要 ?
なぜCSS設計が必要 ? - 名前空間がない - 値の再利用が難しい - Web開発はCSSの弱い言語仕様との闘い
Angularでは ?
Angularでは、既存のCSS設計は不要
Angularでは、既存のCSS設計は不要 Angularそのものが強力な設計である - Component - Scoped CSS
しかし、AngularにおいてもCSSの問題は多くある
しかし、AngularにおいてもCSSの問題は多くある Angularを知り、より良いアプローチが必要
今日の話 1. AngularにはどんなCSSがあるか 2. どう値を共通化できるか
AngularにはどんなCSSがあるか
AngularにはどんなCSSがあるか 1. Component CSS 2. Shared CSS 3. Global CSS
Component CSS - 1つのComponentに対して専用のCSS - CSSは読み込まれたComponentの中にだけ適 用される
Component CSS hero.component.css / .heroes { margin: 8px; padding: 0;
width: 256px; } .hero-item { cursor: pointer; position: relative; } hero.component.ts @Component({ selector: 'app-hero', templateUrl: './hero.component.html', styleUrls: ['./hero.component.css'], }) export class HeroComponent { }
Shared CSS - 複数Componentに対して共通のCSS - CSSは読み込まれたComponentの中にだけ 適用される
Shared CSS hero-common.css / .hero-common-layout { display: block; padding: 8px;
} .hero-common-table { border-collapse: collapse; } .hero-common-form fieldset { border: 0; } villain.component.ts @Component({ selector: 'app-villain', templateUrl: './villain.component.html', styleUrls: ['./hero-common.css'], }) export class VillainComponent {} hero.component.ts @Component({ selector: 'app-hero', templateUrl: './hero.component.html', styleUrls: ['./hero-common.css'], }) export class HeroComponent {}
Global CSS - 全Componentに対して共通に適用される - 普通のCSS
Global CSS style.css / .app-primary-color { color: red; } .app-flex-layout
{ display: flex; } .app-margin-1x { margin: 8px; } angular,json { ... "styles": [ "style.css" ], ... }
それぞれのCSSの使い分け
Component CSS Shared CSS Global CSS 全てのCSSの基本。このCSSだけでアプリケーションが構成できるのが理想。 名前空間は使わず、本質的でシンプルな名前を使う。 - 例)
.button, .card, .list ページ用のComponentのレイアウトなど、Componentにしづらい共通部分に使用。 名前空間 & ユニークなclass名を使用し、必ず定義元を特定できるようにする。 - 例) .hero-common-layout, .hero-common-form フレームワークとしてのCSSに使用する。(オリジナルなUtil系のCSSなど) 名前空間 & ユニークなclass名を使用し、必ず定義元を特定できるようにする。 - 例) .app-flex-layout, .app-margin-1x
おすすめ - Component CSSを使い、Global CSSを使用しない - 良いCSS設計とは、良いComponent設計 - 複数ComponentにまたがるShared CSSが多い場合は、
Component設計を見直す
どう値を共通化できるか どのようにしてアプリケーション全体に 散らばる値を共通化するか ?
Sass (SCSS) を使用する - 変数 - Mixin - 前述の3種類のCSSの値をSassのレベルで共通化
変数 / Mixin などのSass設定値 Component CSS Shared CSS Global CSS
Sassの設定値から、各CSSファイルをトランスパイル
ディレクトリ構造と読み込み Project Structure - src - app - assets -
environments - styles - variables/ - mixins/ - _common.scss ... _common.scss @import './variables/index'; @import './mixins/index'; hero.component.scss @import 'common'; villain.component.scss @import 'common'; angular,json { ... "stylePreprocessorOptions": { "includePaths": [ "src/styles" ] }, ... }
変数とMixinの使い所
変数 Mixin 色や数値など、値に関するものは変数にして、積極的に名前を付ける。 変数の上書きは禁止。全ファイルで読み込む変数はユニークな名前にする。 - 例) $layout-base-padding: 8px - 例)
$primary-color: #4CAF50 まとまった単位でのstyleのセットを共通化する時に使用する。 値のセットはCSSのclassで共通化するよりも、Mixinを使用する。 - 例) font, line-height, letter-spacing など関連する値をまとめる時
おすすめ - Sassの機能を積極的に使う - 値は変数として命名する - 正しい変数名は、それ自体がドキュメントになる
CSSの分け方 / 値の共通の仕方
CSSの分け方 / 値の共通の仕方 まだまだ、その他のアプローチも考えられる
まずは、何よりも - 半年後にすぐに消せるコードを書くこと - CSSのコードは一番変わりやすい - どうすればメンテナンスしやすいかと考える意識が重要
Thank you !!