'how to make same width of various menus?
I have datePickerRange(), Input() and Dropdown(), their width are different, like showing below(white area). Thank you so much for your help
dcc.DatePickerRange(id='date-range',
min_date_allowed=datetime(2020,1,1),
max_date_allowed=datetime.today(),
start_date=datetime(2021,10,30),
end_date=datetime(2021,11,2),
style = {
'font-size': '3px','display': 'inline-block', 'border-radius' : '2px',
'border' : '1px solid #ccc', 'color': '#333',
'border-spacing' : '0', 'border-collapse' :'separate'
}
)
]
),
dbc.Label('DTS Heatmap Start Time:'),
dcc.Input(id="starttime", type="text", value='00:00',placeholder='22:00'),
dbc.Label('DTS Heatmap End Time:'),
dcc.Input(id="endtime", type="text", value='00:00',placeholder='18:00'),
dbc.Label('DTS Data Frequency'),
dcc.Dropdown(id='data-frequency-dropdown',
options=[
{'label':'Minutes','value':'Minutes'},
{'label':'Daily','value':'Daily'},
{'label':'Weekly','value':'Weekly'},
{'label':'Monthly','value':'Monthly'},
],
value='Minutes',
),
How to make their width the same? Thanks
Solution 1:[1]
To set the same width for both components, you can add CSS styling using the width attribute. So if you want to set an explicit width for both components, you can do something like:
dcc.DatePickerRange(id='date-range',
min_date_allowed=dt(2020,1,1),
max_date_allowed=dt.today(),
start_date=dt(2021,10,30),
end_date=dt(2021,11,2),
style = {
'font-size': '3px','display': 'inline-block', 'border-radius' : '2px',
'border' : '1px solid #ccc', 'color': '#333',
'border-spacing' : '0', 'border-collapse' :'separate',
# New CSS styling for width
'width':'500px'
}
)
dcc.Input(
id="starttime",
type="text",
value='00:00',
placeholder='22:00',
# New CSS styling for width
style={'width':'500px'}
)
Please note that if you give the DatePickerRange component a width larger than what it needs to display the date ranges, then it'll show some extra padding that may seem undesirable. If you want to give the input the exact width that the DatePickerRange has by default, then give it "width":"288px" , as this is approximately the default width DatePickerRange has.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Al Mouiee |

