In fact, Mark's way might be the most elegant way as it results in less CQ Template script, with the only compromise being that you might (but most likely not) need to use Class Name's which might not be consistent with your Class naming convention.
Another way to achieve it is to use a Kendo UI Hash Template in the CQ Template, which exist for exactly this purpose, which provide If, Else If, Else output control as detailed in the below post:
https://www.awareim.com/forum/viewtopic.php?p=42455#p42455
I'd say that a hybrid of Mark's way in conjunction with a Kendo Ui Hash Template will be best - use the Hash Template to resolve the appropriate Class Name based on the Value in the Gender field ..
if gender = male then class_name_if_male
else class_name_if_female
..this way your class names can be consistent with your class naming convention.
AND .. you can use the Hash Template to "cheat" and not create classes just for this minor output pattern, by using the Hash Template to specify the different background colors for male and female in the CQ Template directly.