0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Angular】タグに直接スタイルを指定

0
Posted at

方法① HTMLタグに直接指定する(インラインスタイル)

普通のHTMLでも使える書き方

<p style="color: red; font-size: 20px;">
  こんにちは
</p>

image.png

  • style 属性の中に、CSSのプロパティと値を直接書いている
    • color: red:文字色を赤にする
    • font-size: 20px:文字サイズを20pxにする
  • このようにすれば、CSSファイルを別途用意しなくても指定できる

方法② Angularのプロパティバインディングを使う

// app.component.ts
textColor = 'blue';
<p [style.color]="textColor">
  こんにちは
</p>

image.png

textColor の値を p 要素の style.color プロパティに反映している

Angular Materialコンポーネントの場合はさらに選択肢が+1

例:Angular Material独自の色指定

<mat-icon color="primary">home</mat-icon>
  • primary など、そのコンポーネントが対応している値を指定する
    →Angular Materialのテーマに沿った色になる
  • 対応する値や色の適用方法は、Materialのバージョンやテーマ設定によって異なる
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?