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>