CSS背景图片不起作用

CSS背景图片不起作用

本文介绍了ng build --base-href ="/.../"; --deploy-url =“"/.../"CSS背景图片不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"@ angular/core":〜8.0.0",

"@angular/core": "~8.0.0",

带scss样式选项的脚手架Angular 8项目

scaffold angular 8 project with scss style option

我在组件scss文件中具有如下所述的代码

i have code for as mentioned below in component scss file

使用命令最终完成

ng build --prod --base-href="/website/" --deploy-url="/website/"

在子文件夹中放入构建根/网络端

put build at sub folderroot/webside

除背景图片路径之外的所有其他东西

everything working fine except background image path

我已经尝试通过ip/website/assets/images/vector-icon.png到那时我就能得到图像了.

i have tried by ip/website/assets/images/vector-icon.pngat that point i am able to get image.

如果我不更改每个CSS文件的路径怎么办?

What if i don't wont to change the path at every css file.

任何帮助将不胜感激.预先感谢

any help would be appreciated. thanks in advance

推荐答案

解决方案是将"rebaseRootRelativeCssUrls":true放入angular.json文件中.

The solution is to put "rebaseRootRelativeCssUrls": true in the angular.json file.

资产前的/正确.(url(/assets/img ...))

The / before assets is correct.( url(/assets/img...) )

 "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
           ...
           "rebaseRootRelativeCssUrls": true

这篇关于ng build --base-href ="/.../"; --deploy-url =“"/.../"CSS背景图片不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:46