Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Markup (HTML, XHTML, XML) _ Trying to add color to a link

Posted by: KenHorse Sep 27 2018, 12:11 PM

Consider the following snippet of PHP:

CODE
print "    
                
<td align=\"center\">";
if($row[changed]){print "<B><RED>";}                      
print "<a href=\"editmacrorc.php?id=$row[id]&port=$port&tab=$tab\">";    


The tag <RED> is a CSS entry that works fine in other code I use:

CODE

RED {color:red}


As you may see, we read in data from a MySQL database and if the 'changed' field contains a '1', we want to make the displayed character bolded and also RED. And if that character is clicked, take us to the new php file (that all works fine). But only the BOLD is displayed but it is not in RED.

Not really sure if this an HTML or PHP issue but help! biggrin.gif

Posted by: Darin McGrew Sep 27 2018, 04:11 PM

QUOTE(KenHorse @ Sep 27 2018, 10:11 AM) *
The tag <RED>
There is no <RED> element in HTML. It's not surprising that browsers don't recognize it.

Posted by: Darin McGrew Sep 27 2018, 04:12 PM

Please see the FAQ entry http://htmlhelp.com/faq/html/design.html#colors

Posted by: KenHorse Sep 27 2018, 04:15 PM

Not to be argumentative but I clearly posted that my color tag works properly otherwise and included the tag in my css file

Posted by: Christian J Sep 27 2018, 04:19 PM

QUOTE(KenHorse @ Sep 27 2018, 07:11 PM) *

The tag <RED> is a CSS entry that works fine in other code I use:

CODE

RED {color:red}


There is no RED element/tag in HTML, but since browsers don't know that it can still be (ab)used as a CSS selector. It doesn't work on links though, since they use their own color styling. Compare with this:

CODE

<style>KenHorse {color: red;}</style>

...

<KenHorse>ordinary text that's red <a href="">a link with its default color</a></KenHorse>


What I'd do is give the link a CLASS attribute value (depending on the value of $row[changed]), and then use that CLASS value as a selector for the CSS. Something like this:

CODE
if($row[changed])
{
    print '<a class="changed" ';
}
else
{
    print '<a class="unchanged" '; // Or no CLASS attribute at all, if you use default styling.
}                    
print 'href="editmacrorc.php ...

Then you can style the link's CLASS (together with its visited, unvisited, hovered etc states as shown here: https://www.w3.org/TR/2011/REC-CSS2-20110607/selector.html#link-pseudo-classes ).

Nit pick: as a sidenote it's good practice to encode ampersands in URLs: http://htmlhelp.com/tools/validator/problems.html.en#amp).

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)