Search code examples
angularimagetagsbackground-image

IMG tags not working, but background-image working


I'm using Angular 14 and ASP.NET 6 background-image working but img tag not working. How can I solve this problem?

BankSearch.html

<body>
    <div class="container">
      <img src="res/hand.png" alt="hand" width="200"/>
    </div>
</body>

BankSearch.css

body {
    background-image:url("res/hand.png");
  background-color: #F3F3F3;
  background-size:auto;
}

Solution

  • I'm using Angular 14 and actually this problem coming from Angular. Angular looking assets/ folder for source. I solved this problem like this; I moved my res folder to assets folder. My working code:

    <img class="handimg" src="../../assets/res/hand.png" alt="hand" />