Currently I’m doing something like this:
<?php
if ($x == 0)
$image = 'background-position: 0px -7px';
else
$image = 'background-position: 0px -14px';
?>
<a class="asdf" style="<?php echo $image; ?>"></a>
Is this the recommended way to change an image based on a variable in HTML/PHP? Is there any way to refactor this?
Try something like this:
PHP will set which class should be used, and then echo the corresponding class in your HTML. The CSS will be applied with the desired positioning attributes.