描述
我在为“ background”属性提及的url()中收到相对路径错误。
当我使用绝对路径时,似乎工作正常。
错误信息
ERROR in ./src/styles.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--15-3!./src/styles.scss)
Module Error (from ./node_modules/postcss-loader/lib/index.js):
(Emitted value instead of an instance of Error) CssSyntaxError: /home/nithinchandranp/workspace/nithin-portfolio/src/scss/_config.scss:12:24: Can't resolve '../assets/img/DSC_0291.JPG' in '/home/nithinchandranp/workspace/nithin-portfolio/src'
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)@if $show-home-image{ &#bg-img{ background: url(../assets/img/DSC_0291.JPG); ^ background-attachment: fixed; //background-size: cover;
_config.scss
$primary-color:grey;
$show-home-image:true;
//$home-image: url('/src/assets/img/DSC_0291.JPG');
$background-opacity: 0.8;
$overlay-color:black;
$secondary-color:#eece1a;
@mixin background {
@if $show-home-image{
&#bg-img{
background: url(../assets/img/DSC_0291.JPG);
background-attachment: fixed;
//background-size: cover;
&:after {
content: '';
position: fixed;
top: 0;
right: 0;
width: 100%;
height: 100%;
z-index: -1;
background: rgba($overlay-color,$background-opacity);
}
}
} …Run Code Online (Sandbox Code Playgroud)