The Color of links

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

The Color of links

Post by bedcor »

is there a way of stopping a link from changing colors when you click it?

my link <a href...........>.......</a> starts off as blue then when i click it, it turns bright yellow? then when i close the web page and then re-open it, the links are still yellow?
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

This will make all of your links pure blue:

Code: Select all

<body link="#0000FF" alink="#0000FF" vlink="#0000FF">
The link is a regular unvisited link, the alink is the color after you click on it, and the vlink is the color of visited links. If those colors are not specified, the browser picks them.
Last edited by RandomEngy on Fri Jul 26, 2002 3:20 pm, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The best way to do this is to use style sheets (CSS). If you've never used CSS before start here:
http://www.devshed.com/Client_Side/Style_Sheets

The link and alink attributes in the body tag have been deprecated.

The following declaration in a style sheet will cause all links that have been visited or not to be the same colour and gives you a different colour for links when they are hovered over:

Code: Select all

A:link, A:visited &#123;
    color: #ffffcc; /*change the colour to what you want */
&#125;
A:hover &#123;
    color: #ffcccc; /* change the colour when you hover over the link */
&#125;
Mac
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

Or use CSS...
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

D'oh! It appears my solution has been deprecated. I don't see what's wrong with it though. :/
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

how do i use CSS in a php script?

if ($start > 0)
echo "<a href=\"" . $PHP_SELF . "?start=" . ($start - 1) . "\"><center> Previous</center></a>\n\n\n";

if($numrows > ($start + 1))
echo "<a href=\"" . $PHP_SELF . "?start=". ($start + 1) . "\"><center>Next</center></a><BR>";
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

If you post twiglets code in the head of your document between a <style type="text/css"> and a </style> then it will work for all links in your page. If you want do it for individual links you can do <a href="page.html" style="color:blue;">Text</a> or using a class, defined in the style tags in the head like this:

Code: Select all

.special&#123;
    color:blue;
    font-family: Verdana,Sans;
    font-size: 10pt;&#125;
and added to the link like this: <a href="test.html" class="special">Text</a>
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

heh, thats funny :o

It doesnt matter if your using php, using a CSS file treats all <a> tags the same, weather it be in a php script or not...

:)

read twigletmac's post above and follow his link.
bedcor
Forum Newbie
Posts: 24
Joined: Fri Jul 26, 2002 11:01 am
Location: Barrie, Ontario

Post by bedcor »

I'm glad i could make some people laugh with my questions! :)

Thanks for the tips! I got it to work. I used MattF's tip on doing it individually by link.

Thanks again!

One more question!

When i load my form, the first record is displayed and users can browse the contents with the "Next" and "Previous" links. I added a reset button
to clear the form, but when i press it it doesn't do anything?

echo "<input type=reset value=Reset>"
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post by gnu2php »

The reset button doesn't actually clear the form, it just resets the input fields to their default settings.

You can clear all the fields with a simple JavaScript:

Code: Select all

<input type="reset" value="Reset" onClick="clear_form(document.form_name); return false">

<!-- Or you could use document.forms&#1111;0] instead -->


<script language="JavaScript">
<!--
function clear_form(form_obj)
&#123;
	for (var x = 0; x < form_obj.elements.length; x++)
	&#123;
		var type = form_obj.elements&#1111;x].type;

		if (type == 'checkbox' || type == 'radio')
		&#123;
		// These must be cleared this way:
			form_obj.elements&#1111;x].checked = 0;
		&#125;
		else if (type != 'submit' &&
				type != 'reset' &&
				type != 'hidden') // Don't clear these
		&#123;
			form_obj.elements&#1111;x].value = '';
		&#125;
	&#125;
&#125;
//-->
</script>
Note that this doesn't clear <select> fields in Netscape.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Remember that if you do it individually by link then when you change your mind as to how it should appear you have to change every single link. The reason why CSS is so useful is that if you have it separate - ie. separate style from layout - then you only have to change one thing to change a whole site or page...

Please use the link to devshed and read about style sheets.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and that's why I like the microsoft extension "behaviour".
Is there something similar as web-standard?
Post Reply