You need to enable JavaScript to run this app. Plotly Dash-Bootstrap卡片设置color属性后背景及边框颜色未生效问题
优惠活动
大模型
产品
解决方案
定价
更多

Plotly Dash-Bootstrap卡片设置color属性后背景及边框颜色未生效问题

问题解决方法
  • 第一步:检查App初始化时是否引入了Bootstrap样式表
    Dash Bootstrap Components的所有内置样式属性(包括color、inverse/inverted)都依赖Bootstrap样式表生效,初始化App时必须显式指定:
    import dash
    import dash_bootstrap_components as dbc
    
    # 必须添加external_stylesheets参数
    app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
    
    如果你需要用其他主题,也可以替换dbc.themes.BOOTSTRAP为对应主题变量,比如dbc.themes.CYBORG等。
  • 第二步:检查DBC版本对应属性写法
    DBC 1.0及以上版本中,原inverse属性已更名为inverted,如果你使用的是新版本,将inverse=True改为inverted=True即可生效。
  • 第三步:兜底强制覆盖样式
    如果上述方法都无法生效,可以直接在style参数中手动指定卡片样式,效果和内置属性完全一致:
    dbc.Card(
        dbc.CardBody([html.Div([html.H3("Nº DBpedia entities"), html.H3("123")])]),
        style={
            'display': 'inline-block',
            'backgroundColor': '#6c757d', # secondary主题对应色值
            'borderColor': '#6c757d',
            'color': 'white' # 对应inverse/inverted的文字反白效果
        }
    )
    

内容的提问来源于stack exchange,提问作者user15519921

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.14 03:18:03