1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need basic help with Styles and coloring text

Discussion in 'CSS' started by fullylucky, Apr 5, 2020.

  1. #1
    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 ' + '
    $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.
    Solved! View solution.
    fullylucky, Apr 5, 2020 IP
  2. #2

    <td class='text-right'><span style='$style_color'>".$symbol."</span>".$amount."</td>
    Code (markup):
    qwikad.com, Apr 5, 2020 IP
  3. fullylucky

    fullylucky Active Member

    Likes Received:
    Best Answers:
    Trophy Points:
    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.
    fullylucky, Apr 5, 2020 IP
    qwikad.com likes this.
  4. deathshadow

    deathshadow Acclaimed Member

    Likes Received:
    Best Answers:
    Trophy Points:
    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)

      <span', ($symbol == '+' ? '' : ' class="negative"'), '>', $symbol</span>
      ', $amount, '
    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.
    deathshadow, Apr 9, 2020 IP