Home > php教程 > php手册 > body text

PHP生成不同颜色、不同大小的tag标签函数

WBOY
Release: 2016-06-06 20:27:34
Original
1113 people have browsed it

看别人网站上面的tag都是不同颜色,不同大小的tag标签非常不错,这里就分享两个函数,方便需要的朋友

复制代码 代码如下:


function getTagStyle(){
$minFontSize=8; //最小字体大小,可根据需要自行更改
$maxFontSize=18; //最大字体大小,可根据需要自行更改
return 'font-size:'.($minFontSize+lcg_value()*(abs($maxFontSize-$minFontSize))).'px;color:#'.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255));
}

此函数的作用是输出随机的样式,包括font-size和color。

如果你想指定只显示几个字体大小,,而不是完全随机,请将上面的函数代码修改为:

复制代码 代码如下:


function getTagStyle(){
$sizearray = array('8','9','10','11','12','20'); //自定义字体大小,可根据需要自行修改
return 'font-size:'.$sizearray[rand(0,count($sizearray))].'pt;color:#'.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255));
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!