Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
css中背景图像的路径,带有特定的基href_Css_Angular - Fatal编程技术网

css中背景图像的路径,带有特定的基href

css中背景图像的路径,带有特定的基href,css,angular,Css,Angular,angular.json中的baseHref参数为/iofrog/+i18n.locales中定义了7种语言,因此index.html中的最终baseHref为/iofrog/en,用于英语版本 在应用程序组件的css文件中,我有: background-image: url('~/assets/img/background.jpg'); 这被Angular 9 CLI转换为path/iofrog/assets/img/background.jpg,因此跳过了/en/!这是一个错误吗 我还尝

angular.json中的baseHref参数为/iofrog/+i18n.locales中定义了7种语言,因此index.html中的最终baseHref为/iofrog/en,用于英语版本

在应用程序组件的css文件中,我有:

background-image: url('~/assets/img/background.jpg'); 
这被Angular 9 CLI转换为path/iofrog/assets/img/background.jpg,因此跳过了/en/!这是一个错误吗

我还尝试:

background-image: url('/assets/img/background.jpg');  // not showing the image
background-image: url('./assets/img/background.jpg'); // compiler error
background-image: url('assets/img/background.jpg');  // not showing the image
我还发现--rebaserotrelativecssurls=true | false选项,但它被贬值了

正在工作的变通方法在TS中:

this.backgroundImageURL = `url(${this.baseHref}assets/img/background.jpg)`;
在HTML模板中:

[style.background-image]="backgroundImageURL ? backgroundImageURL : ''"
但这并不优雅,图像是在html呈现后加载的


角9中的正确解是什么

i18n building angular app和base href存在一些问题

它应该适用于scss文件的语法:

background-image: url('~src/assets/img/background.jpg');
希望这有帮助