BootStrap5 设置文字颜色为红色

 admin  2025-03-28 11:28:24  51  6  0

在 Bootstrap 5 中,你可以使用内置的文本颜色工具类来设置文字颜色为红色。Bootstrap 5 提供了多种上下文颜色类,其中红色对应的类是 text-danger

示例代码:

<p class="text-danger">这段文字会显示为红色</p>

其他文本颜色类(供参考):

  • text-primary - 蓝色

  • text-secondary - 灰色

  • text-success - 绿色

  • text-warning - 黄色

  • text-info - 浅蓝色

  • text-light - 浅色(通常需要深色背景)

  • text-dark - 深灰色

  • text-muted - 浅灰色

  • text-white - 白色

自定义红色:

如果你想使用更精确的红色,或者 Bootstrap 的 text-danger 不符合你的需求,你可以添加自定义 CSS:

<style>
    .custom-red {
        color: #ff0000; /* 标准红色 */
    }
</style>

<p class="custom-red">自定义红色文字</p>

注意事项:

  1. 确保已正确加载 Bootstrap 5 CSS 文件

  2. 这些文本颜色类可以应用于任何文本元素(<p><span><div> 等)


作者禁止了评论
评论内容