在JS中使用Bootstrap颜色 [英] Using Bootstrap Colors in JS

查看:74
本文介绍了在JS中使用Bootstrap颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google图表,想将切片颜色设置为引导程序使用的颜色,例如badge-successbadge-danger.有什么方法可以从JavaScript中访问这些颜色代码?

I am using a Google-Chart and want to set the slice colors to the color used by bootstrap, e.g., for badge-success or badge-danger. Is there any way to access these color-codes from within JavaScript?

推荐答案

如果您使用的是Bootstrap 4,则此方法有效:

This works if you're using Bootstrap 4:

const root = document.querySelector('html');
getComputedStyle(root).getPropertyValue('--danger');

您可以访问:root伪元素中存在的CSS变量

You can access the CSS variables present in the :root pseudoelement

这篇关于在JS中使用Bootstrap颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆