The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Trying to add color to a link
KenHorse
post Sep 27 2018, 12:11 PM
Post #1





Group: Members
Posts: 3
Joined: 27-September 18
Member No.: 26,719



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

This post has been edited by KenHorse: Sep 27 2018, 12:17 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Sep 27 2018, 04:11 PM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Sep 27 2018, 04:12 PM
Post #3


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



Please see the FAQ entry How can I specify colors?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
KenHorse
post Sep 27 2018, 04:15 PM
Post #4





Group: Members
Posts: 3
Joined: 27-September 18
Member No.: 26,719



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

This post has been edited by KenHorse: Sep 27 2018, 04:15 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 27 2018, 04:19 PM
Post #5


.
********

Group: WDG Moderators
Posts: 9,650
Joined: 10-August 06
Member No.: 7



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-2011060...-pseudo-classes ).

Nit pick: as a sidenote it's good practice to encode ampersands in URLs: ampersands in the URL).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 17th April 2024 - 08:36 PM