You are approaching correctly, but I have changed something.
In css I would do the following:
.foo { background-repeat: no-repeat; background-position: top right; background-size: 140px; }
And in HTML I would save only the URL.
<div class="foo" style="background:url(<?php echo $attribute; ?>);">
Thus, on the server side it is easier to see where you have dynamic content. And you only need to change the URL for the corresponding image.
So, if later you work with another developer, he knows exactly where he should change the images without switching to your css.
source share