简体   繁体   English

如何管理破折号引导组件(dbc)导航栏元素中的按钮对齐?

[英]How to manage buttons alignment in dash bootstrap component (dbc) navbar element?

I guess my problem is with formating html which is created automatically.我想我的问题是格式化自动创建的 html。

I need a navbar with several buttons.我需要一个带有几个按钮的导航栏。 1 on the left, 2 on the right.左边 1 个,右边 2 个。 Between those buttons i need some text.在这些按钮之间,我需要一些文字。

I manged to do that with this code below:我设法用下面的代码做到这一点:

navbar = dbc.NavbarSimple(children=[
    dbc.Button(
        "Меню",
        id="menu_togle",
        n_clicks=0,
        color="secondary",
    ),
    html.H1(children=dashboard_name, style={'textAlign': 'center', 'color':'white'}),
    dbc.Container([
        dbc.Button(
            "Инструкция",
            id="instruction",
            n_clicks=0,
            color="secondary",
            className="me-1"
        ),
        dbc.Button(
            "Изменение параметров дашборда",
            id="open_offcanvas_scrollable",
            n_clicks=0,
            color="secondary",
            className="me-1"
        ),
    ],
    ),
],
color="dark",
dark=True,
fluid=True,
fixed = 'top',
links_left=True,
style={'display': 'flex', 'justify-content': 'space-between'}
)

But HTML looks wierd — has a lots of divs:但是 HTML 看起来很奇怪——有很多 div:

 <nav color="dark" class="navbar navbar-expand-md navbar-dark bg-dark fixed-top" style="display: flex; justify-content: space-between;"> <div class="container-fluid"> <button n_clicks="0" n_clicks_timestamp="-1" type="button" aria-label="Toggle navigation" class="navbar-toggler collapsed"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse"> <div class="me-auto navbar-nav"> <button id="menu_togle" class="btn btn-secondary">Меню</button> <h1 style="text-align: center; color: white;">Дашборд по репрезентативности экспедиции</h1> <div class="container"> <button id="instruction" class="me-1 btn btn-secondary">Инструкция</button> <button id="open_offcanvas_scrollable" class="me-1 btn btn-secondary">Изменение параметров дашборда</button> </div> </div> </div> </div> </nav>

And all classes I add to navbar elements stays only in navbar elements, but not in those divs.我添加到导航栏元素的所有类都只保留在导航栏元素中,而不是那些 div 中。

I also tried to do that with dbc.Row, but that also didn't help (i guess by the same reason).我也尝试使用 dbc.Row 来做到这一点,但这也没有帮助(我猜出于同样的原因)。

Elements looks like that: buttons on navbar元素看起来像这样:导航栏上的按钮

I'd appreciate any help you can give.我很感激你能提供的任何帮助。

EDITED已编辑

I've managed to do something similar to what i need with dbc.ButtonGroup, but some previous leveled div still have margin-end which i couldn't control.我已经设法用 dbc.ButtonGroup 完成了与我需要的类似的事情,但是一些以前的水平 div 仍然有我无法控制的边距。

Code sample:代码示例:

navbar = dbc.NavbarSimple(children=[
        dbc.ButtonGroup([
        
        dbc.Button(
            "Меню",
            id="menu_togle",
            n_clicks=0,
            color="secondary",
            className="me-5"
        ),
        html.H1(children=dashboard_name, style={'textAlign': 'center', 'color':'white'}, className="me-5, ms-5"),
        dbc.ButtonGroup([
            dbc.Button(
                "Инструкция",
                id="instruction",
                n_clicks=0,
                color="secondary",
                className="me-1, ms-5"
            ),
            dbc.Button(
                "Изменение параметров дашборда",
                id="open_offcanvas_scrollable",
                n_clicks=0,
                color="secondary",
                className="ms-1"
            ),
        ],
        ),
        
        ])
    ],
    color="dark",
    dark=True,
    fluid=True,
    fixed = 'top',
    links_left=True,
    style={'display': 'flex', 'justify-content': 'space-between'}
    )

 <nav color="dark" class="navbar navbar-expand-md navbar-dark bg-dark fixed-top" style="display: flex; justify-content: space-between;"> <div class="container-fluid"> <button n_clicks="0" n_clicks_timestamp="-1" type="button" aria-label="Toggle navigation" class="navbar-toggler collapsed"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse"> <div class="me-auto navbar-nav"> <div role="group" class="btn-group"> <button id="menu_togle" class="me-5 btn btn-secondary">Меню</button> <h1 class="me-5, ms-5" style="text-align: center; color: white;">Дашборд по репрезентативности экспедиции</h1> <div role="group" class="btn-group"> <button id="instruction" class="me-1, ms-5 btn btn-secondary">Инструкция</button> <button id="open_offcanvas_scrollable" class="ms-1 btn btn-secondary">Изменение параметров дашборда</button> </div> </div> </div> </div> </div> </nav>

updated navbar with margin on the right更新了导航栏,右侧有边距

I am not shure if its the only right method, but i could fix margins with this method.我不确定它是否是唯一正确的方法,但我可以用这种方法修复边距。

https://community.plotly.com/t/margins-in-dbc-components/65987/4?u=vokiatik https://community.plotly.com/t/margins-in-dbc-components/65987/4?u=vokiatik

That is what i added:这就是我添加的内容:

 .navbar-nav{ margin-right: 0; width: 100%; } #button-container{ width: 100%; justify-content: space-between; text-align: end; } .btn-group-vertical>.btn, .btn-group>.btn { position: relative; flex: inherit; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在引导破折号绘图导航栏中拆分和对齐按钮? (dbc 导航栏) - How to split and align buttons in bootstrap dash plotly navbar? (dbc navbar) 位置破折号引导导航栏 - location dash bootstrap navbar 收到新的 JSON 数据时,如何将 append 新行添加到“dbc.Table.from_dataframe”破折号组件? - How to append new rows to "dbc.Table.from_dataframe" dash component when new JSON data is received? 如何删除破折号 dbc 项目之间的空格? - How to remove whitespace between dash dbc items? DBC(破折号引导组件)不在 pywebview 中呈现; 但是在浏览器中呈现 - DBC (dash bootstrap components ) are not rendered in the pywebview; But renders in the browsers 将图表扩展到 python 中 Dash bootstrap (dbc) 列的完整大小 - Expand graph to the full size of the Dash bootstrap (dbc) column in python dash-bootstrap-components 未正确显示 dbc.Col / dbc.Row - dash-bootstrap-components not displaying dbc.Col / dbc.Row properly "样式化 Accordion dash 引导组件" - Styling Accordion dash bootstrap component 如何在 Dash 表中呈现超链接? (数据表或 dbc 表) - How do I render a hyperlink in a Dash table? (DataTable or dbc Table) 即使屏幕尺寸在 Dash-plotly 中使用 python 更改,如何在导航栏中固定按钮的位置 - How to make the positions of buttons in navbar fixed even when the screen size changes in Dash-plotly with python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM