效果图
实现过程
CSS代码如下
#tag_cloud-2>div>a {
color: #fff;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
padding: 3px 5px;
border: 0;
border-radius: 3px;
display: inline-block;
line-height: 18px;
}
#tag_cloud-2>div>a:hover {
background: #d02f53;
}
JS代码如下
function colorfultags(){
let tags = document.querySelectorAll("#tag_cloud-2 a");
let colorArr = ["#f60", "#45B6F7", "#15a287", "#5cb85c", "#d9534f", "#567e95", "#00a67c", "#b37333"];
let count = 1;
tags.forEach(tag => {
tagsColor = colorArr[count%8];
tag.style.backgroundColor = tagsColor;
count++;
});
}
window.onload=colorfultags();
PJAX回调如下
colorfultags();