引导徽章 HTML
1.引导价值徽章
<span class="badge text-white p-0"><span class="py-1 px-2 rounded" style="background:#5555ff;">value</span></span>
2.引导键值徽章
<span class="badge text-white p-0 m-1"><span class="bg-secondary py-1 px-2 rounded-left">key</span><span class="py-1 px-2 rounded-right" style="background:#007bff;">value</span></span>
在这两种情况下,只需用#5555ff
您的徽章颜色value
和key
您的数据替换即可。
这是他们的样子:

使用 PHP 的动态引导徽章
这个函数只是简单地返回上面的 HTML 并相应地插入颜色、键和值。
function badge($key, $value, $color="5555ff") {
if ($key == "")
return '<span class="badge text-white p-0"><span class="py-1 px-2 rounded" style="background:#' . $color . ';">' . $value . '</span></span>';
return '<span class="badge text-white p-0"><span class="bg-secondary py-1 px-2 rounded-left">' . $key . '</span><span class="py-1 px-2 rounded-right" style="background:#' . $color . ';">' . $value . '</span></span>';
}
然后,您可以badge()
通过以下方式调用该函数:
// value-badge with the default color (here: #5555ff)
echo badge("", "value");
// value-badge with a custom color (here: yellow)
echo badge("", "value", "ffff00");
// key-value-badge with the default color
echo badge("key", "value");
// key-value-badge with a custom color (here: green)
echo badge("key", "value", "00ff00");
资源