Max-width¶
The max-width
style sets a maximum width for a widget.
Syntax¶
max-width: <scalar>;
The max-width
style accepts a <scalar>
that defines an upper bound for the width
of a widget.
That is, the width of a widget is never allowed to exceed max-width
.
Example¶
The example below shows some placeholders that were defined to span horizontally from the left edge of the terminal to the right edge.
Then, we set max-width
individually on each placeholder.
from textual.app import App
from textual.containers import VerticalScroll
from textual.widgets import Placeholder
class MaxWidthApp(App):
CSS_PATH = "max_width.tcss"
def compose(self):
yield VerticalScroll(
Placeholder("max-width: 50h", id="p1"),
Placeholder("max-width: 999", id="p2"),
Placeholder("max-width: 50%", id="p3"),
Placeholder("max-width: 30", id="p4"),
)
if __name__ == "__main__":
app = MaxWidthApp()
app.run()
CSS¶
/* Set the maximum width to 10 rows */
max-width: 10;
/* Set the maximum width to 25% of the viewport width */
max-width: 25vw;
Python¶
# Set the maximum width to 10 rows
widget.styles.max_width = 10
# Set the maximum width to 25% of the viewport width
widget.styles.max_width = "25vw"