我已经看到很多生成随机字体颜色的方法,但是如何在我网站上的一段文字中使用字体列表中的随机字体(或者只是完全随机)?
答案 0 :(得分:5)
您可以从PHP中的列表中获取随机条目,如下所示:
$fonts = array("Helvetica", "Arial", "Comic Sans", "Tahoma");
shuffle($fonts);
$randomFont = array_shift($fonts);
然后只需回显$randomFont
,无论你想要覆盖哪个类。也许在文档中的<style>
标记内嵌
答案 1 :(得分:1)
创建一个字体名称数组。
然后,当您设置文本的颜色时:
var array_ofcolors = ['red', 'blue',...]
obj.style.color =
array_ofcolors[Math.floor(Math.random()*array_ofcolors.length)]
这是一个小提琴:http://jsfiddle.net/maniator/EJAmv/
您可以对字体执行相同的操作:http://jsfiddle.net/maniator/EJAmv/1/
var array_offonts = ["Helvetica", "Arial", "Comic Sans", "Tahoma"]
obj.style.fontFamily =
array_offonts[Math.floor(Math.random()*array_offonts.length)]
答案 2 :(得分:1)
试试这个:
<?php $font = array(
"Arial",
"monospace",
"Comic Sans MS",
"Times",
"Lucida Sans",
"Verdana",
"Helvetica"
);//insert ^there another Fonts
?>
<a style="font-family: <?php echo $font[rand(0,6)]; ?>;" href="#"><h1>Encrypted array <.../> </h1></a>
答案 3 :(得分:0)
这适用于我的网页,我认为这很简单:
<?php
$font =
array(
"Arial",
"monospace",
"Comic Sans MS",
"Times",
"Lucida Sans",
"Verdana",
"Helvetica"
);//insert ^there another Fonts
?>
<style>
*{
font-family: <?php echo($font[rand(1,7)]); ?>;
}
</style>