I've got the following class, which works in all the major browsers except Firefox for PC. Specifically the issue is with the content
being on a regular element—Ffx doesn't seem to like it on anything except a ::before
or ::after
pseudo-element. Trouble is, ::after
does not inherit the size of its base element.
html
<span class="col-3 myImg"></span>
css
.col-3 {
width: 25%;
}
.myImg {
/* content: url('img.png'); works in everything by Ffx on PC */
display: block;
position: relative;
}
/* v Needed for Ffx on PC */
.myImg::after {
background: red;
content: url('img.png');
display: block;
max-width: 100%; /* affects only the background colour */
position: absolute;
width: 100%; /* affects only the background colour */
}
I don't want to set a height—I want the height to stay proportional to the width (which is determined by col-#
from bootstrap v3).
I don't want to use a bunch of image tags because that means an update will require a bunch of edits (instead of one central one to the css).
Related SO question: Can I change the height of an image in CSS :before/:after pseudo-elements?
EDIT I want the image to be 100% the width of the base element (the span) and the image's height to scale proportionately.