mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add a note to the docs about styling tabs
Note that I can't tell if this comes out as I'd like, as right at the moment I can't locally serve the docs due to an error during documentation generation (an issue confirmed by @rodrigogiraoserrao).
This commit is contained in:
25
docs/examples/widgets/tabbed_content_label_color.py
Normal file
25
docs/examples/widgets/tabbed_content_label_color.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Label, TabbedContent, TabPane
|
||||
|
||||
|
||||
class ColorTabsApp(App):
|
||||
CSS = """
|
||||
TabbedContent #--content-tab-green {
|
||||
color: green;
|
||||
}
|
||||
|
||||
TabbedContent #--content-tab-red {
|
||||
color: red;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
with TabbedContent():
|
||||
with TabPane("Red", id="red"):
|
||||
yield Label("Red!")
|
||||
with TabPane("Green", id="green"):
|
||||
yield Label("Green!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ColorTabsApp().run()
|
||||
@@ -94,6 +94,30 @@ The following example contains a `TabbedContent` with three tabs.
|
||||
--8<-- "docs/examples/widgets/tabbed_content.py"
|
||||
```
|
||||
|
||||
## Styling
|
||||
|
||||
The `TabbedContent` widget is composed of two main sub-widgets: a
|
||||
[`Tabs`](tabs.md) and a [`ContentSwitcher`]((content_switcher.md)); you can
|
||||
style them accordingly.
|
||||
|
||||
The tabs within the `Tabs` widget will have prefixed IDs; each ID being the
|
||||
ID of the `TabPane` the `Tab` is for, prefixed with `--content-tab-`. If you
|
||||
wish to style individual tabs within the `TabbedContent` widget you will
|
||||
need to use that prefix for the `Tab` IDs.
|
||||
|
||||
For example, to create a `TabbedContent` that has red and green labels:
|
||||
|
||||
=== "Output"
|
||||
|
||||
```{.textual path="docs/examples/widgets/tabbed_content_label_color.py"}
|
||||
```
|
||||
|
||||
=== "tabbed_content.py"
|
||||
|
||||
```python
|
||||
--8<-- "docs/examples/widgets/tabbed_content_label_color.py"
|
||||
```
|
||||
|
||||
## Reactive Attributes
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|
||||
Reference in New Issue
Block a user