【问题标题】:Why is the index.html in Angular not applying the stylesheet?为什么 Angular 中的 index.html 没有应用样式表?
【发布时间】:2023-03-04 11:52:01
【问题描述】:

我启动了一个 Angular 应用程序,它工作正常,但它没有将样式表 style.css 应用到与 index.html (src) 相同的食物中。知道为什么吗?

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>AngularDemo</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" type="stylesheet" href="style.css">
</head>
<body>
  <i></app-root>
</body>
</html>

style.css

/* You can add global styles to this file, and also import other style files */
body {
  background-color: black;
  color: white;
}

在我将样式添加到 index.html 文件的头部之前,背景保持白色,字母保持黑色。

【问题讨论】:

    标签: html css angular hyperlink styles


    【解决方案1】:

    要解决此问题,请将 type='text/css' 更改为 type='stylesheet'

    type 等于 stylesheet 代表 css 文件,导入任何源。 如你所说,text/css 通常用于 use head 声明。

    【讨论】:

    • 嗨,埃里希!非常感谢您的回答......不幸的是没有任何改变。
    【解决方案2】:

    在 Angular 中,您添加的任何资产都需要在 angular.json 文件中添加其引用。你会在 angular.json 中找到"styles": [ ]。你可以在那里添加你的样式表参考。

    【讨论】:

      【解决方案3】:

      对我来说,如果我将它导入到 CSS 文件中,它会起作用。例如

      @import '@angular/material/prebuilt-themes/indigo-pink.css';
      

      【讨论】:

        猜你喜欢
        • 2021-02-02
        • 1970-01-01
        • 2017-08-09
        • 2013-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-10
        相关资源
        最近更新 更多