The Snippets Thread
10-20-2011, 08:24 AM,
#3
RE: The Snippets Thread
This snippet generates random hexadecimal number to get HTML colors

PHP Code:
<?php 
function get_random_color() 

    for (
$i 0$i<6$i++) 
    { 
        
$color .=  dechex(rand(0,15)); 
    } 
    return 
"$color"

?>

This can be useful to randomize the background color of a website page or a section, such as the header or navigation bars this way:


PHP Code:
<div style="background:#<?php echo $color; ?>;">

or <
body background="#<?php echo $color; ?>;"
MyDigitalpoint PRO Freelance Marketplace
Reply


Messages In This Thread
The Snippets Thread - by MyDigitalpoint - 08-15-2011, 12:00 PM
RE: The Snippets Thread - by HiddenKnowledge - 10-02-2011, 11:35 PM
RE: The Snippets Thread - by MyDigitalpoint - 10-20-2011, 08:24 AM
RE: The Snippets Thread - by Zach - 10-20-2011, 09:37 AM
RE: The Snippets Thread - by Arthur - 10-27-2011, 01:40 PM
RE: The Snippets Thread - by Zach - 10-27-2011, 02:42 PM
RE: The Snippets Thread - by Arthur - 10-27-2011, 09:01 PM
RE: The Snippets Thread - by Serial Thrilla - 01-18-2012, 02:33 AM
RE: The Snippets Thread - by Arthur - 04-12-2012, 07:28 AM

Forum Jump: