0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngularでbodyタグにCSSを当てる方法

Last updated at Posted at 2019-01-28

Angularにはbodyタグが使えない?

前につくったホームページをAngularで再構築してみようということで、
とりあえず、練習としてtopページのhtmlをapp.component.tsのtemplateにそのまま貼ってみた。CSSもstyleに指定して、いざ、表示!

あれ、なんか、スタイルがおかしい?
開発者ツールで見てみると、bodyタグのなかに、htmlタグが入れ子になっていることを確認できた。

CSSを当てる方法

結論として、app.component.tsには、body以下のタグを書くこと!
html,head,bodyタグについては、src配下のindex.htmlに書くこと!
bodyタグのcssはindex.htmlに書くこと!

index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8" />
    <title></title>
    <base href="/" />

    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="~@angular/material/prebuilt-themes/indigo-pink.css"/>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <style type="text/css">
      /* リセットCSS */
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      /* body */
      body {
        background: #ffffff;
        color: #5e5e5e;
        font: 400 87.5%/1.5em "Open Sans", sans-serif;
      }
    </style>
      <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
</head>
  <body>
    <app-root></app-root>
  </body>
</html>

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?