can this be p...">

How to call an image in css?

I am trying to call an image using img

and this is my code:

<img src="/pc/images/leader.png">

can this be put in css? like this code: without using a background image.

CSS

.leader{
  src: /pc/images/leader.png;
}

HTML

  <img class="leader">

thank:)

+4
source share
2 answers

No. You cannot do this with css.

CSS does not use foreground images. You can use only background images.

However, if I understand your problem, you can place the image using a pseudo-element :

.leader::after{
   content: "";
   background: url(path.jpg) no-repeat;
   position:absolute;
   top: 0;
   left: 0;
   width: 50%;
   height: 300px;
}
+6
source
.leader::after{   
   background: url(path.jpg) no-repeat 50% 50%;   
}

if you use 50% 50% then the image will be at centre possition.
0
source

All Articles