Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 6 scss background image not being read

In my angular 6 app I have the following in my scss file:

.pictureplaceholder{
  background-image: url("assets/images/profilepictureplaceholder/PersonPlaceholder.png");
}

that is the correct path to the resource. yet I get this error.

ERROR in ./src/app/venueadmin/parentadminview/venueuserprofile/venueuserprofile.component.scss
(Emitted value instead of an instance of Error) CssSyntaxError: /home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/fixedsuitsandtables/src/app/venueadmin/parentadminview/venueuserprofile/venueuserprofile.component.scss:11:20: Can't resolve 'assets/images/profilepictureplaceholder/PersonPlaceholder.png' in '/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/fixedsuitsandtables/src/app/venueadmin/parentadminview/venueuserprofile'

   9 | 
  10 | .pictureplaceholder{
> 11 |   background-image: url('assets/images/profilepictureplaceholder/PersonPlaceholder.png');
     |                    ^
  12 | }
  13 | 

My other images that are in the assets folder are working. Very strange. Anyone know what this is?

like image 858
weridpotato Avatar asked Jul 04 '18 02:07

weridpotato


People also ask

Why background image is not showing in Div?

I recommend moving your css from the inline scope. Assuming that your . png file actually exists, try setting the background size and repeat tags. If that doesn't work, try checking in your browser's developer tools for the response codes and making sure that the url is correct.

Can Div have image background?

Say you want to put an image or two on a webpage. One way is to use the background-image CSS property. This property applies one or more background images to an element, like a <div> , as the documentation explains.


4 Answers

Add a / to the beginning of each URL.

background-image: url("/../assets/images/profilepictureplaceholder/PersonPlaceholder.png");

based on your directory hierarchy adjust your relative path. But add a forward slash at the beginning.

For more info refer

like image 193
leox Avatar answered Oct 31 '22 16:10

leox


got it. It was a relative path without the ""

so

background-image: url(../../../../assets/images/profilepictureplaceholder/PersonPlaceholder.png);
like image 44
weridpotato Avatar answered Oct 31 '22 18:10

weridpotato


We can use relative path instead of absolute path:

$assetPath: '~src/assets/images/';
$logo-img: '#{$assetPath}logo.png';
@mixin logo {
  background-image: url(#{$logo-img});
}

.logo {
    max-width: 65px;
    @include logo;
 }
like image 26
Aarji George Avatar answered Oct 31 '22 18:10

Aarji George


use in this way

$asset-images-path : "assets/images/imagePathHere";
background-image: image-url("#{$asset-images-path}/imageNameWithExtension.png");
like image 27
dasunse Avatar answered Oct 31 '22 16:10

dasunse