-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How do I style within TabbedContent? #4896
Comments
I have the following
and a snipet of my CSS is
but in the "default" tab, each widget is on its own line (1 column) and also much larger in height so I'm having to scroll down on the screen |
Appreciate any guidance/help/pointers |
You don't need to prefix your IDs. Are you sure none of your CSS is taking effect, or just that the layout isn't quite what you expected? Here's a quick example: from textual.app import App, ComposeResult
from textual.widgets import Label, TabbedContent, TabPane
class ExampleApp(App):
CSS = """
TabbedContent #my-tab {
layout: grid;
grid-size: 4 5;
border: red;
}
Label {
width: 100%;
text-align: center;
border: solid white;
}
"""
def compose(self) -> ComposeResult:
with TabbedContent():
with TabPane("My Tab", id="my-tab"):
for i in range(1, 21):
yield Label(f"{i}")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
with that change
and in my CSS file I now have
I now end up with just the tabs and nothing else on the screen |
hmm so if I completely remove the CSS stuff for the different DataTables/TextAreas...then the layout is "expected" i.e 5 columns across 4 rows...so presumably the # need to be prefixed by the TabbedContent and/or TabPane id? |
Ah they need to be TabbedContent # |
hmm something still not right...if I use
Then that looks as expected..however I update the other widgets in the CSS, then the screen is back to as above?!?!
If the CSS is
Then I see the allocs DT span 3 columns with testA TextArea next to it. However when I then add
Then the screen is like so: |
also I thought the docs said for the TabPane id, it needed to be |
Could you post a screenshot of your app before you added the
I think perhaps you are confusing this with how to style the tab titles, not the content: https://textual.textualize.io/widgets/tabbed_content/#styling |
should look something like ^^ The CSS for that is
and the python is
|
Here's my quick attempt to approximate your layout - am I close? I haven't included the heights of 40/50, as that doesn't seem to be reflected in your screenshot and seem very big! from textual.app import App, ComposeResult
from textual.widgets import DataTable, TabbedContent, TabPane, TextArea
class ExampleApp(App):
CSS = """
#default {
layout: grid;
grid-size: 4 5;
}
#allocs {
column-span: 3;
row-span: 2;
}
#testA {
column-span: 2;
row-span: 2;
}
.foo {
height: 10;
border: round $accent;
}
#testF {
column-span: 3;
border: round $accent;
}
"""
def compose(self) -> ComposeResult:
with TabbedContent():
with TabPane("Default", id="default"):
yield DataTable(id="allocs")
yield TextArea("Some random text", id="testA")
yield DataTable(id="testB", classes="foo")
yield DataTable(id="testC", classes="foo")
yield DataTable(id="testD", classes="foo")
yield DataTable(id="testE", classes="foo")
yield DataTable(id="testF")
def on_mount(self) -> None:
for table in self.query(DataTable):
table.add_columns("C1", "C2", "C3")
table.add_row("R1C1", "R1C2", "R1C3")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
yeah that looks fine when I run it |
By the way, you can use the For example, here's a modified version of my simplified example with a 4x3 grid: from textual.app import App, ComposeResult
from textual.widgets import Label, TabbedContent, TabPane
class ExampleApp(App):
CSS = """
#my-tab {
layout: grid;
grid-size: 4 3;
grid-rows: 15 10 5;
}
#label-1 {
column-span: 3;
}
#label-2 {
column-span: 1;
}
#label-7 {
column-span: 3;
}
Label {
height: 100%;
width: 100%;
content-align: center middle;
border: solid white;
}
"""
def compose(self) -> ComposeResult:
with TabbedContent():
with TabPane("My Tab", id="my-tab"):
for i in range(1, 8):
yield Label(f"{i}", id=f"label-{i}")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Sorted now. Thanks for the help. I'll close this issue |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
Previously I just had some DataTables/TextAreas and within my CSS file I'd specified within the Screen { ... } the layout/grid-size and each DT/TA had an id, which I could also reference (#<my_id>) within the CSS to specify how many rows/columns they spanned etc etc. Now I'm trying to add tabbed content, I basically want all what I had in its own tab, so I can have a completely different layout on another tab...but with TabbedContent, my CSS isn't taking affect...presumably because the layout/screen is now "wrapped" within the TC...I tried changing #<my_id> to TabbedContent #--content-tab-<my_id> without success
The text was updated successfully, but these errors were encountered: