From my answer to this related question:
In the meantime, if you want to be able to resize the :after
pseudo-element and the image that's generated, you will need to apply it as a background image instead and — assuming browser support isn't an issue — use background-size
along with width
and height
to scale it (based on the understanding that those properties apply to the pseudo-element box instead).
So, instead of
content: url("../images/img.png");
use
background-image: url("../images/img.png");
background-size: cover;
(or the shorthand, background: url("../images/img.png") 0 0 / cover
)
As for scaling your pseudo-element proportionally, I think you should be able to accomplish this using the padding-bottom
trick. For an image with a ratio of 1:2, padding-bottom: 200%
seems to work in this example:
.container {
border: thick solid;
margin: 1em;
}
.large.container { width: 100px; }
.small.container { width: 50px; }
.container::after {
content: '';
display: block;
background: url(http://placehold.it/100x200) 0 0 / cover;
padding-bottom: 200%;
}
<div class="large container"></div>
<div class="small container"></div>