✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Dcc component option (css style) not working

Hello, I am working on Dash to build a web application for machine learning.
I tried simple code below to build a dropdown for selection of variable.
When I tried the style width as percentage, it worked properly.
(Ex) style = {“width”:‘50%’})
However, my problem is that my option for css style for dropdown component like this
style = {“width”:’ calc(100%-10px);’}
does not seem to work, just displaying default full size 100% components.
I’ve look through various examples on google, but cannot find the difference.
Is there something else to be considered? Thank you.

import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate

external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

app = dash.Dash(name, external_stylesheets=external_stylesheets, prevent_initial_callbacks=True)
app.layout = html.Div([
{‘label’:‘A’, ‘value’: ‘A’}, {‘label’:‘B’, ‘value’:‘B’}],
value = None, style = {“width”:‘calc(100%-10px);’}),

Output(‘output-dropdown’, ‘children’),
Input(‘input-dropdown’, ‘value’),
prevent_initial_call = True

def select_value(value):
if value is None:
raise PreventUpdate
return value

if name == ‘main’:

Hi @yjkwak

You can use a css file to do that, you need to have a folder named “assets” in the same folder where you have the app.

Any css file in the assets folder will be loaded when the app starts.

In your css file just add this:

#input-dropdown {
  width: calc(100% - 10px);

Thanks, it works perfectly!

1 Like