Bootstrap 4 个徽章不起作用 - 只是没有出现

Bootstrap 4 badge not working - just not showing up

我正在尝试以这种方式使用 bootstrap 4 徽章:

<td><span class="badge badge-warning">{{ object.get_type_display }}</span></td>

我正在使用:

https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css

可能是什么原因?

调试时您的浏览器缓存是否禁用? 这可能是原因。

我建议您使用开发人员工具查看您的 html 输出是否也按预期呈现。

.badge was dropped in the v4:

Dropped the .badge component as it was nearly identical to labels/tags. Use the .tag-pill modifier together with the label component instead for that rounded look.

But they returned it (git issue) so use the latest version - v4.0.0-alpha.6

css 上没有徽章 class。尝试另一个版本(据我所知,有 alpha.6 版本)。使用以下 link: https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css

不正确:

<span class="badge badge-default badge-pill">1</span>

正确:

<span class="badge badge-secondary badge-pill">1</span>

这是不久前的事了,所以它需要更新,因为我发现 alpha 6 不包含所有徽章(即 badge-light)。

今天最好使用最新的最终版本。使用此 cdn 链接进行最终发布 https://www.bootstrapcdn.com/

有一种巧妙的方法可以混淆 badgealert 类。

示例:

<span class="badge alert-success">Active</span>

Walp,我看到这有点老了,但截至目前,bootstrap 4 和 5 支持徽章(与这里有人说的情况相反)...但在 bootstrap 五个中,不是 badge-secondary(或 info 或 primary 或你有什么),而是 bg-secondary(或 info 或 primary 或你有什么。)

这也是徽章背景可能无法显示的(现代)原因。

在第 class="badge badge-warning" 部分你可以在第二部分写 class=badge alert-warning 而不是 badge 关键字,它对我的​​代码有帮助。

你不能使用“badge badge-warning”。根据 Bootstrap 中的新文档,现在它就像 "badge bg-warning"

看看这个:- https://getbootstrap.com/docs/5.0/components/badge/

至少在 Bootstrap 版本 5.1.x 徽章在 v4.

您可以使用以下代码在标题旁边显示徽章

<h1>Example heading <span class="badge bg-secondary">New</span></h1>

现在也支持按钮、背景颜色和药丸徽章。您可以在此处找到文档:https://getbootstrap.com/docs/5.1/components/badge/

它没有用,因为没有应用到徽章的背景颜色。因为 bootstrap 已经有一个 'bg' 背景色组件。我用 'bg-warning' 替换了 'badge-warning' 并且它起作用了。这是最后的样子:

<span class="badge bg-warning">Primary</span>