Here is the existing code: <td class='text-right' style='$style_color'>".$symbol.$amount."</td> Code (markup): $style_color is a dynamic variable that sets the colour to red or green. It is set above this code like this: $style_color = 'color: #FF0000'; in an if statement. $amount just holds a 2 decimal amount. $symbol is ' + ' or $symbol is ' - ' I basically want just the symbol to be red or green but the value to always remain black. How do I update the code to get this? At the moment the output is like this + 350.20 - 20.00 I want it like this: + 350.20 - 20.00 Any help is greatly appreciated.
Try: <td class='text-right'><span style='$style_color'>".$symbol."</span>".$amount."</td> Code (markup):
Hi Qwikad, thanks for the fast response. Sorry for the basic question. I should really just spend a few hours and learn css. Thanks again!! Really appreciate it.
Mind you , style has ZERO huffing business in the markup, you should be saying WHY it's getting SOME sort of colour, not what that colour is. To that end classes like text-right are also mentally enfeebled nonsense -- likely stemming from one of those monuments to developer 3i -- ignorance, incompetence, and ineptitude -- that are front-end frameworks. This looks like numeric output.... since you've got a perfectly good TD I'm wondering why you think you should even have a class on it. Also is this ACTUALLY string addition, or are you in an echo? If the latter, comma delimit instead of adding. (generally slopping markup into strings is bad practice) <td> <span', ($symbol == '+' ? '' : ' class="negative"'), '>', $symbol</span> ', $amount, ' </td> Code (markup): EVERYTHING else there should be handled in your EXTERRNAL stylesheet, not by your markup. I'm assuming your tbody is targetable .parentTbody span { color:green; } .parentTbody span.negative { color:red; } Code (markup): ... or something along those lines. I'd have to see the full table to weigh in better on how the classes should (or shouldn't be) applied/placed. 99.99% of the time you see style="" and 100% of the time you see <style> you're looking at 3i and a complete failure to use HTML or CSS properly. Same goes for any time you see a class that describes what you want it to look like. Even just your tiny snippet is raising all sorts of warning flags on that front for your whole codebase.