简体   繁体   English

Angular 的主 html 文件不能使用 src/styles 文件夹中的 styles.scss 文件

[英]Angular's main html file can't use the styles.scss file inside the src/styles folder

I'm new to Angular.我是 Angular 的新手。

In order to use the 7-1 scss pattern in my project, I created a styles folder inside the src folder "src/styles", and linked the components to the src/styles/style.scss and it works fine.为了在我的项目中使用 7-1 scss 模式,我在 src 文件夹“src/styles”内创建了一个 styles 文件夹,并将组件链接到 src/styles/style.scss,它工作正常。

The problem I'm having now is that the html and body elements within the main index.html file aren't affected by these styles.我现在遇到的问题是主 index.html 文件中的 html 和正文元素不受这些 styles 的影响。

Here's a look at my directory structure下面看一下我的目录结构

I tried importing the styles needed inside the src/styles.scss file and it worked but I don't want to repeat my code.我尝试在 src/styles.scss 文件中导入所需的 styles 并且它有效,但我不想重复我的代码。

  1. Wanted behavior :通缉行为

     The main index.html can use the scss styles inside the "src/styles/styles.scss" I created with no problem.
  2. Actual behavior :实际行为

     The main index.html can only access the default style.scss folder by default

How can I fix this so that the elements inside the index.html can use the styles from within my styles folder without having to repeat my work twice?我该如何解决这个问题,以便 index.html 中的元素可以在我的 styles 文件夹中使用 styles 而不必重复我的工作?

Edit: the problem occurs despite the already made changes to the angular.json file as you can see here编辑:尽管已经对 angular.json 文件进行了更改,但问题仍然存在,如您在此处看到的

Thank you in advance先感谢您

You can add styles in the angular.json .您可以在 angular.json 中添加styles You can find styles array in the file and add the path of the style.您可以在文件中找到styles数组并添加样式的路径。

在此处输入图像描述

you need to add your src/styles/styles.css inside angular.json您需要在 angular.json 中添加您的src/styles/styles.css 8CBA22E28EB17B5F5C6AE2A266AZ

there is style object有款式 object

{ 
  "projects":{
   "yourProjectName": {
     "architect":{
       "build:{
        "options":{
          "assets":[...],
          "styles": [
           "src/styles/styles.scss",
          ]
//..rest of config
        }
      }
    }
  } 
}

Note: After adding please restart your local development server or if in production re-deploy, to see changes注意:添加后请重新启动本地开发服务器,或者如果在生产中重新部署,以查看更改

npm run build after paster below command "npm start" make sure You can find screenshot npm 在命令“npm start”下面粘贴后运行构建确保你可以找到截图

在此处输入图像描述

Solved.解决了。 I was able to solve the problem by importing all the sass files from the src/styles into the main styles.scss file.我能够通过将所有 sass 文件从 src/styles导入主styles.scss文件来解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 angular 组件的styles.scss 中使用媒体查询? - How to use media queries in angular component's styles.scss? 我的styles.scss 根本无法在 html 中工作 - My styles.scss is not working in html at all 如何使用具有样式的html文件通过iTextSharp创建pdf文件 - How I can use a html file with styles for creat a pdf file with iTextSharp Firefox不显示HTML文件的样式 - firefox not displaying styles of html file 我想执行js文件以向html添加样式,但是无法在打字稿中加载js文件 - i want to execute js file for adding styles to html but can't load js file in typescript 在webview中,我们如何使用javascript CSS样式访问HTML文件 - in webview how we can access HTML file with javascript CSS styles SASS样式在保存scss文件时适用,但在浏览器刷新时不适用 - SASS styles apply when saving scss file but not on browser refresh 如何在 HTML 中将其转换为 SCSS 内联 styles - How to convert it SCSS inline styles in your HTML 如何在php文件中使用javascript更改父html文件中的图片src? - How can I use javascript inside of a php file to change an image src in the parent html file? 在HTML文件中编写CSS样式时,可以使用Sass和罗盘吗? 你应该看什么? - Can you use Sass and compass when you write your css styles in your HTML file? What should you watch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM