简体   繁体   中英

Centering a dcc.input field in Plotly Dash

I am trying to center a dcc.input text field to the middle of the screen, however the solutions found here: Plotly Dash center dcc.Input text field nor the https://dash.plotly.com/dash-core-components/input page has proven to fix the problem. My code is:

dcc.Input(
                id="textsearch",
                placeholder='Write your lyrics here and press ENTER...',
                type='text',
                value=None,
                debounce=True,
                style={'width': '20%',"display":"flex", "justifyContent":'center'}
                ),

Ive tried the 'textAlign':'center' as well which works for the html.H6 element above the input bar. Any ideas? See the picture below for reference for what exactly i would like to happen. 在此处输入图像描述

You are applying style on the wrong component. You need to apply that to your Input's parent div.

app.layout = html.Div(
    [
        html.Div(
            children=[
                dcc.Input(
                    id="textsearch",
                    placeholder="Write your lyrics here and press ENTER...",
                    type="text",
                    value="",
                    debounce=True,
                )
            ],
            style={"display": "flex", "justifyContent": "center"},
        )
    ]
)

Also, it's advised to pass "" to your Input if you want it to be empty.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM