What is preferred way to add discount tags over some product image using css?
My current implementation is this http://jsfiddle.net/ANtfG/7/
Html
<ul>
<li class="save_money">
<img src="http://lorempixum.com/200/200/food" />
<span class="twenty-percent" /></span>
</li>
</ul>
CSS
.save_money{position:relative;float:left;margin:15px;background:yellow;display:inline}
.save_money img{position:absolute;}
.twenty-percent{background:url(http://canadianneighborpharmacy.net/images/cnp/discount_20.png);position:absolute; left:170px; top:-2px; width:45px; height:45px}
I want to improve these two restriction in my current implementation or tell me the better way to achieve this
- How to align discount tag to
right, not usingleft:170px?right:0
doesn’t work. and width of product images can be changed sometime
thenleft:170pxwill not be flexible to width. - I’m using a Blank
spanelement in mark-up I would like to know if
there is another way to do it. Why I usedspanover<img>because I
have different tags for 20%, 30%, 40% discount. SO i thought instead
using<img>it would begood to add a span with classes like
.twenty-percent,.thirty-percent,.forty-prcent
Use
right: -15px. That way, when you adjust the width, the “discount tag” will still be positioned correctly.position: absoluteon theimgmust be removed, because with it thelihas no width or height. I addeddisplay: blockto remove the~4pxof yellow space underneath theimgcaused by theimgbeingdisplay: inline.See: http://jsfiddle.net/thirtydot/ANtfG/9/
That’s fine. The only other option would to omit the
spanand use:before– but of course, that won’t work in older browsers such as IE7 (and it won’t quite work in IE8 due to an IE8 bug).See: http://jsfiddle.net/thirtydot/ANtfG/11/
You should fix this:
to this: