制作标签云的基本思路是将关键词以不同的字体大小或颜色呈现出来,较为突出的关键词通常被放大和着色,而较小的关键词则相对比较沉淀。在 CSS 中制作标签云的方法有很多,以下是一些示例代码:
.tag-cloud {
display: flex;
flex-wrap: wrap;
}
.tag-cloud a {
display: inline-block;
font-size: 16px;
padding: 5px;
margin: 5px;
color: #fff;
background-color: #666;
border-radius: 50%;
transform: scale(1);
transition: all 0.2s ease-in-out;
}
.tag-cloud a:hover {
transform: scale(1.1);
}
.tag-cloud{
position: relative;
padding-top: 20px;
text-align: center;
}
.tag-cloud a{
display: inline-block;
margin-right: 10px;
margin-bottom: 10px;
padding: 8px 20px;
background-color: #f44336;
color:#FFF;
font-family: Arial, sans-serif;
font-size: 10pt;
text-decoration: none;
border-radius: 4px;
}
.tag-cloud a:hover{
animation: bounce 0.6s infinite alternate;
}
@keyframes bounce{
to{transform: translateY(-10px);}
}
.tag-cloud{
text-align: center;
}
.tag-cloud a{
position: relative;
display: inline-block;
margin-bottom: 10px;
margin-right: 10px;
padding: 8px 20px;
background-color: #f44336;
color:#FFF;
font-family: Arial, sans-serif;
font-size: 10pt;
text-decoration: none;
border-radius: 4px;
}
.tag-cloud a:before, .tag-cloud a:after{
content:"";
position: absolute;
z-index: -1;
bottom: -6px;
left: 0;
width: 100%;
height: 50%;
background: linear-gradient(rgba(0, 0, 0, 0.2) 60%, rgba(0, 0, 0, 0));
transform: skew(-15deg) rotate(-6deg);
transition: all 0.2s ease-in-out;
}
.tag-cloud a:after{
transform: skew(15deg) rotate(6deg);
}
.tag-cloud a:hover:after, .tag-cloud a:hover:before{
transform: skew(-15deg) rotate(-3deg);
background: linear-gradient(rgba(0, 0, 0, 0.2) 40%, rgba(0, 0, 0, 0));
bottom: -8px;
}
以上是三种不同的 CSS 制作标签云的示例代码, 分别使用了 CSS3 的 transform 和 transition 属性、 animate 属性,以及伪元素。您可以根据实际需要调整其中的字体大小、颜色和字体样式等元素,使标签云达到最佳效果。