在 Plotly Dash 中对齐 2 html.Divs 个文本

Aligning 2 html.Divs of text next to each other in Plotly Dash

我试图并排放置 2 个 Div 元素,但没有成功。我一直在关注 https://community.plotly.com/t/horizontally-stack-components/10806https://medium.com/analytics-vidhya/dash-for-beginners-dash-plotly-python-fcd1fe02b749 使用 width<50% 和 'display' 的指南:'inline-block' 但运气不好。

如果你看附件图片,它看起来像应该在右边的块,实际上,直到我通过选择列表中的一首歌曲来更新页面以在左侧显示歌词,然后它将建议推到底部。有什么想法吗?

我的代码如下所示:

html.Div([
            html.Div(id="lyrics",style={'width': '50%', 'display': 'inline-block'}),
            html.Div([
            html.H6(id="recommendations",children="Recommendations:"),
            html.H3(id="songsbysameartist",children='Songs by the same artist:',
                    ),
            html.H6(id="sameartistrecommendations",
                    ),
            html.H3(id="songsfromotherartists",children='Music from other artists that you might also like:',
                   ),
            html.H6(id="otherartistrecommendations",
                )
            ],
            style = {'width': '30%', 'display': 'inline-block'})
            ])

编辑后的代码如下所示:

html.Div([
            html.Div(id="lyrics",style={'width': '50%', 'display': 'inline-block'}),
            html.Div([
            html.H6(id="recommendations",children="Recommendations:"),
            html.H3(id="songsbysameartist",children='Songs by the same artist:',
                    ),
            html.H6(id="sameartistrecommendations",
                    ),
            html.H3(id="songsfromotherartists",children='Music from other artists that you might also like:',
                   ),
            html.H6(id="otherartistrecommendations",
                )
            ],
            style = {'width': '30%', 'display': 'flex'})
            ])

因为底部样式连接到父级 Div 据我所知,以上建议。

我找到了解决方案:

我认为错误出在结构上。父 Div 需要有 "display":"flex" 而 2 个子 Div 元素有 "display":"inline-block".

正确的代码是这样的:

html.Div([
                    html.Div([
                        html.Div(id="songandartist",style={'display': 'flex',"fontSize" : 40,"marginBottom":50}),
                        html.Div(id="lyrics",style={'display': 'flex'}
                        )
                    ],style={'width': '49%', 'display': 'inline-block'}),
                    html.Div([
                        html.Div(id="recommendations",children="Recommendations:",style={"fontSize" : 40,"marginBottom":50,'display': 'flex'}),
                        html.Div(id="songsbysameartist",style={"fontSize" : 27,'display':'flex'},children='Songs by the same artist:',
                        ),
                        html.Div(id="sameartistrecommendations",style={"marginBottom":50,'whiteSpace': 'pre-line','display': 'flex'}
                        ),
                        html.Div(id="songsfromotherartists",style={"fontSize" : 27,'display': 'flex'},children='Music from other artists that you might also like:',
                       ),
                        html.Div(id="otherartistrecommendations",style={'whiteSpace': 'pre-line','display': 'flex'}
                    )
                    ],
                style = {'width': '49%', 'display': 'inline-block'})
                ],style={"display": "flex"})