-1

I have tried to get after pseudo for image but nothing appears ,Is this a wrong way or we can't have :after :beforfe for inline elements.

img:after{
position:absolute;
width:100%;
height:100%;
background:red;
right:-100%;
}

img{
position:relative;
}
<img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSkokrxxIX-EDiBFHl7z-gDrIscZSa2KDgl5Xm1-31053Zb1yvb"/>

3 Answers3

0

yes this is wrong way to use ::after & ::before you can add a parent div of img than you can use ::before and ::after

0

There are a few basics you need to know like, use of content:'' and figure.

figure:after{
    content:''; /*if you are using :after or :before you have to use content*/
    position:absolute;
    width:100%;
    height:100%;
    background:red;
    right:-100%;
}

figure{
    position:relative;
    width: 400px; /*just for test*/
}
<figure> <!-- HTML5 :) -->
    <img src="http://t3.gstatic.com/images?q=tbn:ANd9GcSkokrxxIX-EDiBFHl7z-gDrIscZSa2KDgl5Xm1-31053Zb1yvb"
     >
</figure>
agravat.in
  • 561
  • 6
  • 14
0

I respect all answers but it doesn't work with img tag, you have to use a parent to make it work with img tag. Although it works with other inline tage like a,span etc. Hope it will help you.

One thing please do add content:""; whenever you do css for before and after Thanks

Amarjit Singh
  • 1,152
  • 7
  • 12