我正在try 在仪表板的顶部添加一个横幅.目前,顶部的包含显示卡片和一个侧栏.有没有办法把柱子往下推,并在上面加一条横幅.

我还希望将右侧图形的高度扩展到与左侧的两个图形相同的高度.

我已经附上了当前布局的屏幕截图,其中一些箭头突出了预期的布局.

from dash import Dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px

# generic card
card = dbc.Card(
    [
        dbc.CardHeader("This is the header"),
        dbc.CardBody(
            [
                html.H4("Card title", className="card-title"),
                html.P("This is some card text", className="card-text"),
            ]
        ),
        dbc.CardFooter("This is the footer"),
    ],
    className='text-center m-4'
)

external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]

app = Dash(__name__, external_stylesheets = external_stylesheets)

# Set up the layout with a single graph
app.layout = dbc.Container([
    dbc.Row([
        # to be used as a sidebar
        dbc.Col(html.Div("stuff", className="bg-secondary h-100"), width=2),
        dbc.Col([
            dbc.Row([
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card)
            ]),
            dbc.Row([
                dbc.Col(dcc.Graph(), style={
                        "padding-top": "10px",
                        "padding-bottom": "10px",
                    },),
            ]),
            dbc.Row([
                dbc.Col([dcc.Graph()]),
            ]),
        ], width=5),
        dbc.Col([
            dbc.Row([
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card),
            ]),
            dbc.Row([
                dbc.Col([dcc.Graph()]),
            ], className="h-100"),
        ], width=5),
    ])
], fluid=True)


if __name__ == '__main__':
    app.run(debug=True)

enter image description here

推荐答案

我认为你应该在卡片上面多加一行,你将需要将3个图表合并成一个有2列的行,并改变右侧图表的高度.

请判断以下代码:

from dash import Dash
from dash import dcc
from dash import html
import dash_bootstrap_components as dbc
import pandas as pd
import plotly.express as px

df = px.data.gapminder()
fig = px.area(df, x="year", y="pop", color="continent", line_group="country")
# generic card
card = dbc.Card(
    [
        dbc.CardHeader("This is the header"),
        dbc.CardBody(
            [
                html.H4("Card title", className="card-title"),
                html.P("This is some card text", className="card-text"),
            ]
        ),
        dbc.CardFooter("This is the footer"),
    ],
    className='text-center m-4'
)

external_stylesheets = [dbc.themes.SPACELAB, dbc.icons.BOOTSTRAP]

app = Dash(__name__, external_stylesheets = external_stylesheets)

# Set up the layout with a single graph
app.layout = dbc.Container([
    dbc.Row([
        html.Img(src=r'assets/hong-kong-skyline-panorama.jpg', alt='image')
    ]),
    dbc.Row([
        # to be used as a sidebar
        dbc.Col(html.Div("stuff", className="bg-secondary h-100"), width=2),
        dbc.Col([
            dbc.Row([
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card),
                dbc.Col(card)
            ]),
            dbc.Row([
                dbc.Col([dbc.Card(dcc.Graph(figure=fig),style={'height':400}),
                         dbc.Card(dcc.Graph(figure=fig),style={'height':400})
                        ], width=6),
                dbc.Col([dbc.Card(dcc.Graph(figure=fig,style={'height':800}),style={'height':800})], width=6),            
            ]),
        ], width=10),
    ], className='p-2 align-items-stretch')
], fluid=True)


if __name__ == '__main__':
    app.run(debug=True)

And here is the result: enter image description here enter image description here

Css相关问答推荐

将CSS栅格行高设置为其余视口高度

如何在Bootstrap 5上使用移动设备居中内容?

背景图像允许溢出输入按钮

具有水平和垂直滚动的表格上的活动 scss 类

有没有办法将px单位添加到 Sass mixin 的参数数组中?

如何阻止 Mud Blazor MudTable 列扩展以适合文本

问题定位位置:Tailwindcss 中的绝对元素

flex 容器中的两个滚动块

我无法在 next.js 应用程序中传播 daisyui 的主题

CSS3 - RotateY() 居中

使用 CSS 无限期地闪烁两个不同持续时间的文本

基于类的 CSS Select 器

将复选框对齐到中心

如何使单选按钮看起来像切换按钮

如何在 Chrome 中模拟偏好 colored颜色 方案媒体查询?

flexbox 布局中的 Padding-bottom/top

如何将页脚保持在屏幕底部

加载资源失败:服务器响应状态为 404(未找到)

如何使 window.scrollTo() 效果平滑

打印html时在页面上打印页码