Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using image in angular

Tags:

css

angular

I have images stored in images folder inside assets folder

app 
  -app.component.css
assets
  -images
     -some-image.png

I'm trying to get the image in css inside background-image, but I think I have path related issues, since I can't seem to bring the image.

background-image:  url(../../../assets/images/some-image.png) no-repeat center top;

Help would be appreciated.

like image 923
Michael Philips Avatar asked Oct 22 '25 03:10

Michael Philips


2 Answers

Try adding the style as following with a width and height. Also, isolate the background-repeat and background-position. It'd work.

  background-image:  url(../assets/images/some-image.png);
  background-repeat: no-repeat;
  background-position: center-top;
  width: 100%; // any width
  height: 230px; // any height

To make it look better you can add,

background-size: contain;

UPDATE:

The reason that the image doesn't show up without width and height, As default div is given a height of 0 since there are no inner elements. But, it has a default width of 100% already. Therefore, when we add an image using CSS background image property, we've to add the height attribute.

like image 89
Saiyaff Farouk Avatar answered Oct 24 '25 18:10

Saiyaff Farouk


It should be just,

background-image:  url(../assets/images/some-image.png) no-repeat center top;
like image 43
Sajeetharan Avatar answered Oct 24 '25 18:10

Sajeetharan