I’m trying to set the relative height of the contents of a tab to match that of its parent by setting style={"height":"100%"} for a dcc.Tab component. My layout consists of an html.Div with a 100% viewport height.
Here’s the simplest example I could think of. I expected orange_div to fill up the page. Forcing orange_div to have style={"height":"100vh"} will do this, but for my application the units need to be %, not vh or px.
from dash import Dash, html, dcc
app = Dash(name=__name__)
orange_div = html.Div(
children=["Tab contents should fill the window height."],
style={
"height": "100%", # not inheriting parent height
"background-color": "orange",
},
)
tabs = dcc.Tabs(dcc.Tab(orange_div, label="Tab 1", style={"height": "100%"}))
app.layout = html.Div(tabs, style={"height": "100vh"})
if __name__ == "__main__":
app.run_server(debug=True)
Hi @payton-dev , thanks for the reply. Unfortunately, it’s important that orange_div inherits its height from its parent and doesn’t use a viewport height. A real world example would be two rows of content where one has an absolute height (e.g., 200px) and the other needs to use the remainder of the vertical space. Depending on the size of the browser window, the second row will use a different fraction of the viewport height.
Hi @jinnyzor , thanks for the suggestion. I’ve added a fixed-height top_div to better illustrate my issue. Adding "min-height":"100%" (or “minHeight”) didn’t have an effect.
I think the issue is with the height of dcc.Tab not responding to the style property how I’d expect it to. Even if I set dcc.Tab to have style={"height": "500px"}, the tab content height doesn’t change.
Thank you! I was missing both content_style and parent_style in dcc.Tabs. Both seem to be needed if using "height":"100%".
Unfortunately, this causes dcc.Tab to have 100vh in addition to the 200px element at the top. But this issue is independent of dcc.Tabs and almost certainly stems from my misunderstanding of CSS, so I’m marking this as solved. Thanks!