Random font color
How can I fil开发者_运维百科l text with 2 or 3 random colors?
You can make it with javascript.
There are 16777215 colors so...
function randomColor() {
return '#' + ('00000' + (Math.random() * 16777216 << 0).toString(16)).substr(-6);
}
There you go - random color generator though some outputted colors might be wee ugly - I warned you!
(there was nice talk about random color generation at Paul Irish's blog.)
This is how I do it with CSS and javascript (the code here is for random colors and random sizes):
<head>
<style>
div {
position: relative;
float: left;
display: inline-block;
margin-right: 15px;
}
</style>
<script type="text/javascript">
function randomColors() {
document.write("<div style='color:#" + Math.floor(Math.random()*4096).toString(16) + ";font-size: " + Math.floor(Math.random()*24+12) + "px;'>");
}
</script>
</head>
<body>
<script>randomColors()</script>Sentence1 </div>
<script>randomColors()</script>Sentence2 </div>
<script>randomColors()</script>Sentence3 </div>
etc.
Each Sentence gets its unique color and unique size (from 12px up to 35px).
精彩评论