|
-
Mar 18th, 2005, 04:36 AM
#1
Thread Starter
Hyperactive Member
Font and Table color settings
hey guys, plz how can i set FONT color, TABLE bgcolor and its bordercolor randomly, may be using Javascript so that the font and table will have different color settings each time the HTML page is loaded
<font color=???> where ??? will not be fixed so that i can randomly generate a color value for it.
Oyad
Nobody is smarter than all of us!
-
Mar 19th, 2005, 06:17 PM
#2
Fanatic Member
Re: Font and Table color settings
HTML Code:
<html>
<head>
<title>Random Colors</title>
<style type = "text/css">
body {color:red;}
table {background:blue; border-style: solid; border-color: red;}
</style>
<script type = "text/javascript">
function randomColor(){
r = Math.round(Math.random() * 255);
g = Math.round(Math.random() * 255);
b = Math.round(Math.random() * 255);
base = r / 16;
rem = r % 16;
base = base - (rem / 16);
baseR = ConvertToHex(base);
remR = ConvertToHex(rem);
base = g / 16;
rem = g % 16;
base = base - (rem / 16);
baseG = ConvertToHex(base);
remG = ConvertToHex(rem);
base = b / 16;
rem = b % 16;
base = base - (rem / 16);
baseB = ConvertToHex(base);
remB = ConvertToHex(rem);
hexnum = '#' + baseR +remR + baseG + remG + baseB + remB;
return hexnum;
}//end randomColor
function ConvertToHex(num) {
if((num >= 0) && (num <= 9))
return num;
else {
switch(num) {
case 10: return "A";
case 11: return "B";
case 12: return "C";
case 13: return "D";
case 14: return "E";
case 15: return "F";
}//end switch
}//end else
}//end ConvertToHex
function changeTableColor(){
tblMain.style.borderColor = randomColor();
}
function changeFontColor(){
tblMain.style.color = randomColor();
}
</script>
</head>
<body onload = "changeFontColor();changeTableColor();">
<h1>Random Colors</h1>
</ br>
<table ID = "tblMain">
<tr><td>table cell</td></tr>
</table>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|