question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to tell a child widget to be 100% the height of the parent widget

See original GitHub issue

Given this code:

from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Static

class HeightApp( App[ None ] ):

    CSS = """
    Horizontal {
        border: solid red;
        height: auto;
    }

    Static {
        border: solid green;
        width: auto;
    }

    #fill_parent {
        height: auto;
    }

    #static {
        height: 23;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Horizontal(
            Static( "How to make this as tall as container?", id="fill_parent" ),
            Static( "This has default\nheight\nbut a\nfew lines" ),
            Static( "I have a static height", id="static" ),
        )

if __name__ == "__main__":
    HeightApp().run()

this is the output: Screenshot 2022-12-05 at 12 08 10 Now imagine you want to make the first widget exactly as tall as the containing widget. Given all other things seen in CSS, it feels like you should be able to set the height of fill_parent to 100% and it will vertically fill the parent – in effect matching the height of the tallest non-relative-sized widget. But if I do that the widget does this instead: Screenshot 2022-12-05 at 12 09 07 It’s as if it is taking the height from the container’s container, or simply the Screen.

Note the same happens if height is set to 1fr.

Raising this issue to first check if this is the expected behaviour.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
willmcgugancommented, Dec 8, 2022

Should be fixed in main. Making that column expand is now as simple as:

height: 100%;
1reaction
davepcommented, Dec 5, 2022

If I’m understanding you correctly… that’s fine, the enclosing Horizontal avoids those:

Screenshot 2022-12-05 at 15 53 20

I’ve not dived into the code yet (this issue is for future investigation for me as much as anything), but I feel like there could be a tweak to be had here regarding deciding which child height wins when trying to decide the best height.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I layout widgets based on the size of the parent?
You will want to use the LayoutBuilder widget which will build at layout time and provides the parent widget's constraints.
Read more >
Child Widget is always clipped by Parent Size #54551 - GitHub
When a Child Widget attempts to exceed the size of the Parent, it is clipped. ... 100), child: Container( width: 100, height: 100, ......
Read more >
How to Set Child Widget Width Equal to Parent in Flutter
This error occurs when the parent widget has an infinite container and the child widget has infinite width or height.
Read more >
Can anyone explain widget Constraints? I am not able to wrap ...
If you want to set a widget to 25% of the width and/or height of the parent widget, there's a FractionallySizedBox and an...
Read more >
Flutter: The Advanced Layout Rule Even Beginners Must Know
A widget gets its own constraints from its parent. A “constraint” is just a set of 4 doubles: a minimum and maximum width,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found