【发布时间】:2022-01-18 12:32:04
【问题描述】:
我试图并排放置 2 个 Div 元素,但没有运气。我一直在关注 https://community.plotly.com/t/horizontally-stack-components/10806 和 https://medium.com/analytics-vidhya/dash-for-beginners-dash-plotly-python-fcd1fe02b749 指导使用 width
如果您查看附加的图片,它看起来应该是向右的块,实际上是,直到我通过在列表中选择一首歌曲来更新页面以在左侧显示歌词,然后它推动底部的建议。有什么想法吗?
我的代码如下所示:
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'})
])
【问题讨论】:
-
你考虑过使用dash-bootstrap-components吗?在这里,您可以使用行和列在适合您需要的布局中排列内容。
-
同样使用
display: flex作为父div应该可以很好地完成这项工作。 -
@MrLeeh 我实际上没有考虑过,它是否还包括具有相同功能的下拉菜单等?我已经在核心组件中完成了这一切,所以我宁愿让它与那个 :D 一起工作,尝试过 display: flex,但它不能正常工作。使用 display: flex 它只是将整个推荐块始终放在左侧
-
你能发布带有 display: flex 的代码吗?把它应用到父母身上很重要。孩子不应该有显示属性。
-
@MrLeeh 是的先生,我现在在主文档中添加了一段编辑过的代码:-)
标签: python plotly plotly-dash plotly-python