HTML + CSS 实现 GitHub 项目标签、徽章样式


经常会在GitHub上项目介绍的README.md文件中看到许多漂亮的标签,这些标签可以显示version、stars、license等信息
Shields
我们可以通过 https://shields.io/ 这个网站在线制作图标,填写label、message、color三个字段,点击Make Badge就可以生成图标,还有其他功能可以自己去体验。
在这里插入图片描述
我们也可以通过 HTML + CSS 来实现:

CSS

.github-badge {
	display: inline-block;
	border-radius: 4px;
	text-shadow: none;
	font-size: 12px;
	color: #fff;
	line-height: 15px;
	background-color: #ABBAC3;
  margin-bottom: 5px;
}
.github-badge .badge-subject {
	display: inline-block;
	background-color: #4D4D4D;
	padding: 4px 4px 4px 6px;
	border-top-left-radius: 4px;
	border-bottom-left-radius: 4px;
}
.github-badge .badge-value {
	display: inline-block;
	padding: 4px 6px 4px 4px;
	border-top-right-radius: 4px;
	border-bottom-right-radius: 4px;
}
.github-badge .bg-brightgreen {
	background-color: #4DC820 !important;
}
.github-badge .bg-orange {
	background-color: #FFA500 !important;
}
.github-badge .bg-yellow {
	background-color: #D8B024 !important;
}
.github-badge .bg-blueviolet {
	background-color: #8833D7 !important;
}
.github-badge .bg-pink {
	background-color: #F26BAE !important;
}
.github-badge .bg-red {
	background-color: #e05d44 !important;
}
.github-badge .bg-blue {
	background-color: #007EC6 !important;
}
.github-badge .bg-lightgrey {
	background-color: #9F9F9F !important;
}
.github-badge .bg-grey, .github-badge .bg-gray {
	background-color: #555 !important;
}
.github-badge .bg-lightgrey, .github-badge .bg-lightgray {
	background-color: #9f9f9f !important;
}

HTML

  <div class="github-badge">
    <span class="badge-subject">Powered</span><span class="badge-value bg-blue">Hexo</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject">Hosted</span><span class="badge-value bg-brightgreen">GitHub</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject">DNR</span><span class="badge-value bg-firebrick">Aliyun</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject">CDN</span><span class="badge-value bg-orange">jsDelivr</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject">PictureBed</span><span class="badge-value bg-blueviolet">SM.MS</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject">Theme</span><span class="badge-value bg-blue">Material X</span>
  </div>
  <div class="github-badge">
    <span class="badge-subject"><i class="fa fa-copyright"></i></span><span class="badge-value bg-lightgrey">BY-NC-SA 4.0</span>
  </div>

最终效果

在这里插入图片描述
参考资料:CSS - Badge

TRHX • 鲍勃 CSDN认证博客专家 CSDN博客专家 网络爬虫工程师 高校俱乐部主席
个人博客:www.itrhx.com,Python 网络爬虫工程师,专攻数据挖掘、数据分析,数据可视化领域,Golang、前端以及开源技术爱好者,一入 IT 深似海,从此学习无绝期!求知若饥,虚心若愚,只谈技术,莫问前程!注重细节,用心写好文!
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页